OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/common/pref_names.h" |
| 6 #include "chrome/browser/prefs/pref_service.h" |
| 7 #include "chrome/browser/ui/tab_contents/per_tab_prefs_tab_helper.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 10 #include "content/browser/tab_contents/test_tab_contents.h" |
| 11 #include "content/test/test_browser_thread.h" |
| 12 |
| 13 using content::BrowserThread; |
| 14 |
| 15 class PerTabPrefsTabHelperTest : public TabContentsWrapperTestHarness { |
| 16 public: |
| 17 PerTabPrefsTabHelperTest() |
| 18 : TabContentsWrapperTestHarness(), |
| 19 ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 20 |
| 21 virtual ~PerTabPrefsTabHelperTest() {} |
| 22 |
| 23 TabContentsWrapper* contents_wrapper2() { |
| 24 return contents_wrapper2_.get(); |
| 25 } |
| 26 |
| 27 void SetContents2(TestTabContents* contents) { |
| 28 contents_wrapper2_.reset( |
| 29 contents ? new TabContentsWrapper(contents) : NULL); |
| 30 } |
| 31 |
| 32 protected: |
| 33 virtual void SetUp() OVERRIDE { |
| 34 TabContentsWrapperTestHarness::SetUp(); |
| 35 SetContents2(CreateTestTabContents()); |
| 36 } |
| 37 |
| 38 virtual void TearDown() OVERRIDE { |
| 39 contents_wrapper2_.reset(); |
| 40 TabContentsWrapperTestHarness::TearDown(); |
| 41 } |
| 42 |
| 43 private: |
| 44 content::TestBrowserThread ui_thread_; |
| 45 scoped_ptr<TabContentsWrapper> contents_wrapper2_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(PerTabPrefsTabHelperTest); |
| 48 }; |
| 49 |
| 50 TEST_F(PerTabPrefsTabHelperTest, PerTabJavaScriptEnabled) { |
| 51 const char* key = prefs::kWebKitJavascriptEnabled; |
| 52 PrefService* prefs1 = contents_wrapper()->per_tab_prefs_tab_helper()->prefs(); |
| 53 PrefService* prefs2 = |
| 54 contents_wrapper2()->per_tab_prefs_tab_helper()->prefs(); |
| 55 const bool initial_value = prefs1->GetBoolean(key); |
| 56 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); |
| 57 |
| 58 prefs1->SetBoolean(key, !initial_value); |
| 59 EXPECT_EQ(!initial_value, prefs1->GetBoolean(key)); |
| 60 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); |
| 61 |
| 62 prefs1->SetBoolean(key, initial_value); |
| 63 EXPECT_EQ(initial_value, prefs1->GetBoolean(key)); |
| 64 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); |
| 65 |
| 66 prefs2->SetBoolean(key, !initial_value); |
| 67 EXPECT_EQ(initial_value, prefs1->GetBoolean(key)); |
| 68 EXPECT_EQ(!initial_value, prefs2->GetBoolean(key)); |
| 69 } |
OLD | NEW |