OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 #include "base/prefs/scoped_user_pref_update.h" | 6 #include "base/prefs/scoped_user_pref_update.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_web_ui.h" | 9 #include "chrome/browser/extensions/extension_web_ui.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/common/extensions/manifest_url_handler.h" | 13 #include "chrome/common/extensions/manifest_url_handler.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 19 #include "extensions/test/result_catcher.h" |
19 | 20 |
20 using content::WebContents; | 21 using content::WebContents; |
21 | 22 |
22 class ExtensionOverrideTest : public ExtensionApiTest { | 23 class ExtensionOverrideTest : public ExtensionApiTest { |
23 protected: | 24 protected: |
24 bool CheckHistoryOverridesContainsNoDupes() { | 25 bool CheckHistoryOverridesContainsNoDupes() { |
25 // There should be no duplicate entries in the preferences. | 26 // There should be no duplicate entries in the preferences. |
26 const base::DictionaryValue* overrides = | 27 const base::DictionaryValue* overrides = |
27 browser()->profile()->GetPrefs()->GetDictionary( | 28 browser()->profile()->GetPrefs()->GetDictionary( |
28 ExtensionWebUI::kExtensionURLOverrides); | 29 ExtensionWebUI::kExtensionURLOverrides); |
(...skipping 14 matching lines...) Expand all Loading... |
43 seen_overrides.insert(value); | 44 seen_overrides.insert(value); |
44 } | 45 } |
45 | 46 |
46 return true; | 47 return true; |
47 } | 48 } |
48 }; | 49 }; |
49 | 50 |
50 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideNewtab) { | 51 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideNewtab) { |
51 ASSERT_TRUE(RunExtensionTest("override/newtab")) << message_; | 52 ASSERT_TRUE(RunExtensionTest("override/newtab")) << message_; |
52 { | 53 { |
53 ResultCatcher catcher; | 54 extensions::ResultCatcher catcher; |
54 // Navigate to the new tab page. The overridden new tab page | 55 // Navigate to the new tab page. The overridden new tab page |
55 // will call chrome.test.notifyPass() . | 56 // will call chrome.test.notifyPass() . |
56 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab/")); | 57 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab/")); |
57 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 58 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
58 ASSERT_TRUE(tab->GetController().GetVisibleEntry()); | 59 ASSERT_TRUE(tab->GetController().GetVisibleEntry()); |
59 EXPECT_TRUE(tab->GetController().GetVisibleEntry()->GetURL(). | 60 EXPECT_TRUE(tab->GetController().GetVisibleEntry()->GetURL(). |
60 SchemeIs(extensions::kExtensionScheme)); | 61 SchemeIs(extensions::kExtensionScheme)); |
61 | 62 |
62 ASSERT_TRUE(catcher.GetNextResult()); | 63 ASSERT_TRUE(catcher.GetNextResult()); |
63 } | 64 } |
(...skipping 24 matching lines...) Expand all Loading... |
88 // Times out consistently on Win, http://crbug.com/45173. | 89 // Times out consistently on Win, http://crbug.com/45173. |
89 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
90 #define MAYBE_OverrideHistory DISABLED_OverrideHistory | 91 #define MAYBE_OverrideHistory DISABLED_OverrideHistory |
91 #else | 92 #else |
92 #define MAYBE_OverrideHistory OverrideHistory | 93 #define MAYBE_OverrideHistory OverrideHistory |
93 #endif // defined(OS_WIN) | 94 #endif // defined(OS_WIN) |
94 | 95 |
95 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) { | 96 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) { |
96 ASSERT_TRUE(RunExtensionTest("override/history")) << message_; | 97 ASSERT_TRUE(RunExtensionTest("override/history")) << message_; |
97 { | 98 { |
98 ResultCatcher catcher; | 99 extensions::ResultCatcher catcher; |
99 // Navigate to the history page. The overridden history page | 100 // Navigate to the history page. The overridden history page |
100 // will call chrome.test.notifyPass() . | 101 // will call chrome.test.notifyPass() . |
101 ui_test_utils::NavigateToURL(browser(), GURL("chrome://history/")); | 102 ui_test_utils::NavigateToURL(browser(), GURL("chrome://history/")); |
102 ASSERT_TRUE(catcher.GetNextResult()); | 103 ASSERT_TRUE(catcher.GetNextResult()); |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
106 // Regression test for http://crbug.com/41442. | 107 // Regression test for http://crbug.com/41442. |
107 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, ShouldNotCreateDuplicateEntries) { | 108 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, ShouldNotCreateDuplicateEntries) { |
108 const extensions::Extension* extension = | 109 const extensions::Extension* extension = |
(...skipping 25 matching lines...) Expand all Loading... |
134 ExtensionWebUI::kExtensionURLOverrides); | 135 ExtensionWebUI::kExtensionURLOverrides); |
135 update.Get()->Set("history", list); | 136 update.Get()->Set("history", list); |
136 } | 137 } |
137 | 138 |
138 ASSERT_FALSE(CheckHistoryOverridesContainsNoDupes()); | 139 ASSERT_FALSE(CheckHistoryOverridesContainsNoDupes()); |
139 | 140 |
140 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("override/history"))); | 141 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("override/history"))); |
141 | 142 |
142 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes()); | 143 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes()); |
143 } | 144 } |
OLD | NEW |