Home | History | Annotate | Download | only in prefs
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/prefs/session_startup_pref.h"
      6 #include "chrome/common/pref_names.h"
      7 #include "chrome/test/testing_pref_service.h"
      8 #include "testing/gmock/include/gmock/gmock.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 // Unit tests for SessionStartupPref.
     12 class SessionStartupPrefTest : public testing::Test {
     13  public:
     14   virtual void SetUp() {
     15     pref_service_.reset(new TestingPrefService);
     16     SessionStartupPref::RegisterUserPrefs(pref_service_.get());
     17   }
     18 
     19   scoped_ptr<TestingPrefService> pref_service_;
     20 };
     21 
     22 TEST_F(SessionStartupPrefTest, URLListIsFixedUp) {
     23   ListValue* url_pref_list = new ListValue;
     24   url_pref_list->Set(0, Value::CreateStringValue("google.com"));
     25   url_pref_list->Set(1, Value::CreateStringValue("chromium.org"));
     26   pref_service_->SetUserPref(prefs::kURLsToRestoreOnStartup, url_pref_list);
     27 
     28   SessionStartupPref result =
     29       SessionStartupPref::GetStartupPref(pref_service_.get());
     30   EXPECT_EQ(2u, result.urls.size());
     31   EXPECT_EQ("http://google.com/", result.urls[0].spec());
     32   EXPECT_EQ("http://chromium.org/", result.urls[1].spec());
     33 }
     34 
     35 TEST_F(SessionStartupPrefTest, URLListManagedOverridesUser) {
     36   ListValue* url_pref_list1 = new ListValue;
     37   url_pref_list1->Set(0, Value::CreateStringValue("chromium.org"));
     38   pref_service_->SetUserPref(prefs::kURLsToRestoreOnStartup, url_pref_list1);
     39 
     40   ListValue* url_pref_list2 = new ListValue;
     41   url_pref_list2->Set(0, Value::CreateStringValue("chromium.org"));
     42   url_pref_list2->Set(1, Value::CreateStringValue("chromium.org"));
     43   url_pref_list2->Set(2, Value::CreateStringValue("chromium.org"));
     44   pref_service_->SetManagedPref(prefs::kURLsToRestoreOnStartup,
     45                                 url_pref_list2);
     46 
     47   SessionStartupPref result =
     48       SessionStartupPref::GetStartupPref(pref_service_.get());
     49   EXPECT_EQ(3u, result.urls.size());
     50 
     51   SessionStartupPref override_test =
     52       SessionStartupPref(SessionStartupPref::URLS);
     53   override_test.urls.push_back(GURL("dev.chromium.org"));
     54   SessionStartupPref::SetStartupPref(pref_service_.get(), override_test);
     55 
     56   result = SessionStartupPref::GetStartupPref(pref_service_.get());
     57   EXPECT_EQ(3u, result.urls.size());
     58 }
     59