OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/pref_names.h" | 5 #include "chrome/common/pref_names.h" |
6 #include "chrome/browser/prefs/pref_service.h" | 6 #include "chrome/browser/prefs/pref_service.h" |
7 #include "chrome/browser/ui/tab_contents/per_tab_prefs_tab_helper.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" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
9 #include "chrome/browser/ui/tab_contents/test_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" | 10 #include "content/browser/tab_contents/test_tab_contents.h" |
11 #include "content/test/test_browser_thread.h" | 11 #include "content/test/test_browser_thread.h" |
12 | 12 |
13 using content::BrowserThread; | 13 using content::BrowserThread; |
14 | 14 |
| 15 class TestPerTabPrefsTabHelper : public PerTabPrefsTabHelper { |
| 16 public: |
| 17 explicit TestPerTabPrefsTabHelper(TabContentsWrapper* tab_contents) |
| 18 : PerTabPrefsTabHelper(tab_contents), |
| 19 was_override_web_prefernces_called_(false) { |
| 20 } |
| 21 virtual ~TestPerTabPrefsTabHelper() { } |
| 22 |
| 23 virtual void OverrideWebPreferences(WebPreferences* prefs) OVERRIDE { |
| 24 was_override_web_prefernces_called_ = true; |
| 25 PerTabPrefsTabHelper::OverrideWebPreferences(prefs); |
| 26 } |
| 27 |
| 28 void NotifyRenderViewCreated() { |
| 29 RenderViewCreated(NULL); |
| 30 } |
| 31 |
| 32 bool was_override_web_prefernces_called() { |
| 33 return was_override_web_prefernces_called_; |
| 34 } |
| 35 |
| 36 private: |
| 37 bool was_override_web_prefernces_called_; |
| 38 }; |
| 39 |
15 class PerTabPrefsTabHelperTest : public TabContentsWrapperTestHarness { | 40 class PerTabPrefsTabHelperTest : public TabContentsWrapperTestHarness { |
16 public: | 41 public: |
17 PerTabPrefsTabHelperTest() | 42 PerTabPrefsTabHelperTest() |
18 : TabContentsWrapperTestHarness(), | 43 : TabContentsWrapperTestHarness(), |
19 ui_thread_(BrowserThread::UI, &message_loop_) {} | 44 ui_thread_(BrowserThread::UI, &message_loop_) {} |
20 | 45 |
21 virtual ~PerTabPrefsTabHelperTest() {} | 46 virtual ~PerTabPrefsTabHelperTest() {} |
22 | 47 |
23 TabContentsWrapper* contents_wrapper2() { | 48 TabContentsWrapper* contents_wrapper2() { |
24 return contents_wrapper2_.get(); | 49 return contents_wrapper2_.get(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); | 85 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); |
61 | 86 |
62 prefs1->SetBoolean(key, initial_value); | 87 prefs1->SetBoolean(key, initial_value); |
63 EXPECT_EQ(initial_value, prefs1->GetBoolean(key)); | 88 EXPECT_EQ(initial_value, prefs1->GetBoolean(key)); |
64 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); | 89 EXPECT_EQ(initial_value, prefs2->GetBoolean(key)); |
65 | 90 |
66 prefs2->SetBoolean(key, !initial_value); | 91 prefs2->SetBoolean(key, !initial_value); |
67 EXPECT_EQ(initial_value, prefs1->GetBoolean(key)); | 92 EXPECT_EQ(initial_value, prefs1->GetBoolean(key)); |
68 EXPECT_EQ(!initial_value, prefs2->GetBoolean(key)); | 93 EXPECT_EQ(!initial_value, prefs2->GetBoolean(key)); |
69 } | 94 } |
| 95 |
| 96 TEST_F(PerTabPrefsTabHelperTest, OverridePrefsOnViewCreation) { |
| 97 TestPerTabPrefsTabHelper* test_prefs_helper = new TestPerTabPrefsTabHelper( |
| 98 contents_wrapper()); |
| 99 contents_wrapper()->per_tab_prefs_tab_helper_.reset(test_prefs_helper); |
| 100 EXPECT_EQ(false, test_prefs_helper->was_override_web_prefernces_called()); |
| 101 test_prefs_helper->NotifyRenderViewCreated(); |
| 102 EXPECT_EQ(true, test_prefs_helper->was_override_web_prefernces_called()); |
| 103 } |
OLD | NEW |