Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: chrome/browser/extensions/api/url_overrides/url_overrides_apitest.cc

Issue 11660016: Move the parsing of "chrome_url_overrides" out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/extensions/extension_service.h" 6 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_web_ui.h" 7 #include "chrome/browser/extensions/extension_web_ui.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/prefs/scoped_user_pref_update.h" 9 #include "chrome/browser/prefs/scoped_user_pref_update.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/browser_tabstrip.h" 12 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/common/extensions/api/url_overrides/url_overrides_handler.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "extensions/common/constants.h" 18 #include "extensions/common/constants.h"
18 19
19 using content::WebContents; 20 using content::WebContents;
20 21
21 class ExtensionOverrideTest : public ExtensionApiTest { 22 class URLOverridesApiTest : public ExtensionApiTest {
22 protected: 23 protected:
23 bool CheckHistoryOverridesContainsNoDupes() { 24 bool CheckHistoryOverridesContainsNoDupes() {
24 // There should be no duplicate entries in the preferences. 25 // There should be no duplicate entries in the preferences.
25 const DictionaryValue* overrides = 26 const DictionaryValue* overrides =
26 browser()->profile()->GetPrefs()->GetDictionary( 27 browser()->profile()->GetPrefs()->GetDictionary(
27 ExtensionWebUI::kExtensionURLOverrides); 28 ExtensionWebUI::kExtensionURLOverrides);
28 29
29 const ListValue* values = NULL; 30 const ListValue* values = NULL;
30 if (!overrides->GetList("history", &values)) 31 if (!overrides->GetList("history", &values))
31 return false; 32 return false;
32 33
33 std::set<std::string> seen_overrides; 34 std::set<std::string> seen_overrides;
34 for (size_t i = 0; i < values->GetSize(); ++i) { 35 for (size_t i = 0; i < values->GetSize(); ++i) {
35 std::string value; 36 std::string value;
36 if (!values->GetString(i, &value)) 37 if (!values->GetString(i, &value))
37 return false; 38 return false;
38 39
39 if (seen_overrides.find(value) != seen_overrides.end()) 40 if (seen_overrides.find(value) != seen_overrides.end())
40 return false; 41 return false;
41 42
42 seen_overrides.insert(value); 43 seen_overrides.insert(value);
43 } 44 }
44 45
45 return true; 46 return true;
46 } 47 }
47 }; 48 };
48 49
49 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideNewtab) { 50 IN_PROC_BROWSER_TEST_F(URLOverridesApiTest, OverrideNewtab) {
50 ASSERT_TRUE(RunExtensionTest("override/newtab")) << message_; 51 ASSERT_TRUE(RunExtensionTest("override/newtab")) << message_;
51 { 52 {
52 ResultCatcher catcher; 53 ResultCatcher catcher;
53 // Navigate to the new tab page. The overridden new tab page 54 // Navigate to the new tab page. The overridden new tab page
54 // will call chrome.test.notifyPass() . 55 // will call chrome.test.notifyPass() .
55 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab/")); 56 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab/"));
56 WebContents* tab = chrome::GetActiveWebContents(browser()); 57 WebContents* tab = chrome::GetActiveWebContents(browser());
57 ASSERT_TRUE(tab->GetController().GetActiveEntry()); 58 ASSERT_TRUE(tab->GetController().GetActiveEntry());
58 EXPECT_TRUE(tab->GetController().GetActiveEntry()->GetURL(). 59 EXPECT_TRUE(tab->GetController().GetActiveEntry()->GetURL().
59 SchemeIs(extensions::kExtensionScheme)); 60 SchemeIs(extensions::kExtensionScheme));
60 61
61 ASSERT_TRUE(catcher.GetNextResult()); 62 ASSERT_TRUE(catcher.GetNextResult());
62 } 63 }
63 64
64 // TODO(erikkay) Load a second extension with the same override. 65 // TODO(erikkay) Load a second extension with the same override.
65 // Verify behavior, then unload the first and verify behavior, etc. 66 // Verify behavior, then unload the first and verify behavior, etc.
66 } 67 }
67 68
68 #if defined(OS_MACOSX) 69 #if defined(OS_MACOSX)
69 // Hangy: http://crbug.com/70511 70 // Hangy: http://crbug.com/70511
70 #define MAYBE_OverrideNewtabIncognito DISABLED_OverrideNewtabIncognito 71 #define MAYBE_OverrideNewtabIncognito DISABLED_OverrideNewtabIncognito
71 #else 72 #else
72 #define MAYBE_OverrideNewtabIncognito OverrideNewtabIncognito 73 #define MAYBE_OverrideNewtabIncognito OverrideNewtabIncognito
73 #endif 74 #endif
74 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideNewtabIncognito) { 75 IN_PROC_BROWSER_TEST_F(URLOverridesApiTest, MAYBE_OverrideNewtabIncognito) {
75 ASSERT_TRUE(RunExtensionTest("override/newtab")) << message_; 76 ASSERT_TRUE(RunExtensionTest("override/newtab")) << message_;
76 77
77 // Navigate an incognito tab to the new tab page. We should get the actual 78 // Navigate an incognito tab to the new tab page. We should get the actual
78 // new tab page because we can't load chrome-extension URLs in incognito. 79 // new tab page because we can't load chrome-extension URLs in incognito.
79 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( 80 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord(
80 browser()->profile(), GURL("chrome://newtab/")); 81 browser()->profile(), GURL("chrome://newtab/"));
81 WebContents* tab = chrome::GetActiveWebContents(otr_browser); 82 WebContents* tab = chrome::GetActiveWebContents(otr_browser);
82 ASSERT_TRUE(tab->GetController().GetActiveEntry()); 83 ASSERT_TRUE(tab->GetController().GetActiveEntry());
83 EXPECT_FALSE(tab->GetController().GetActiveEntry()->GetURL(). 84 EXPECT_FALSE(tab->GetController().GetActiveEntry()->GetURL().
84 SchemeIs(extensions::kExtensionScheme)); 85 SchemeIs(extensions::kExtensionScheme));
85 } 86 }
86 87
87 // Times out consistently on Win, http://crbug.com/45173. 88 // Times out consistently on Win, http://crbug.com/45173.
88 #if defined(OS_WIN) 89 #if defined(OS_WIN)
89 #define MAYBE_OverrideHistory DISABLED_OverrideHistory 90 #define MAYBE_OverrideHistory DISABLED_OverrideHistory
90 #else 91 #else
91 #define MAYBE_OverrideHistory OverrideHistory 92 #define MAYBE_OverrideHistory OverrideHistory
92 #endif // defined(OS_WIN) 93 #endif // defined(OS_WIN)
93 94
94 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) { 95 IN_PROC_BROWSER_TEST_F(URLOverridesApiTest, MAYBE_OverrideHistory) {
95 ASSERT_TRUE(RunExtensionTest("override/history")) << message_; 96 ASSERT_TRUE(RunExtensionTest("override/history")) << message_;
96 { 97 {
97 ResultCatcher catcher; 98 ResultCatcher catcher;
98 // Navigate to the history page. The overridden history page 99 // Navigate to the history page. The overridden history page
99 // will call chrome.test.notifyPass() . 100 // will call chrome.test.notifyPass() .
100 ui_test_utils::NavigateToURL(browser(), GURL("chrome://history/")); 101 ui_test_utils::NavigateToURL(browser(), GURL("chrome://history/"));
101 ASSERT_TRUE(catcher.GetNextResult()); 102 ASSERT_TRUE(catcher.GetNextResult());
102 } 103 }
103 } 104 }
104 105
105 // Regression test for http://crbug.com/41442. 106 // Regression test for http://crbug.com/41442.
106 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, ShouldNotCreateDuplicateEntries) { 107 IN_PROC_BROWSER_TEST_F(URLOverridesApiTest, ShouldNotCreateDuplicateEntries) {
107 const extensions::Extension* extension = 108 const extensions::Extension* extension =
108 LoadExtension(test_data_dir_.AppendASCII("override/history")); 109 LoadExtension(test_data_dir_.AppendASCII("override/history"));
109 ASSERT_TRUE(extension); 110 ASSERT_TRUE(extension);
110 111
111 // Simulate several LoadExtension() calls happening over the lifetime of 112 // Simulate several LoadExtension() calls happening over the lifetime of
112 // a preferences file without corresponding UnloadExtension() calls. 113 // a preferences file without corresponding UnloadExtension() calls.
113 for (size_t i = 0; i < 3; ++i) { 114 for (size_t i = 0; i < 3; ++i) {
114 ExtensionWebUI::RegisterChromeURLOverrides( 115 ExtensionWebUI::RegisterChromeURLOverrides(
115 browser()->profile(), 116 browser()->profile(),
116 extension->GetChromeURLOverrides()); 117 extensions::URLOverridesInfo::GetChromeURLOverrides(extension));
117 } 118 }
118 119
119 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes()); 120 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes());
120 } 121 }
121 122
122 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, ShouldCleanUpDuplicateEntries) { 123 IN_PROC_BROWSER_TEST_F(URLOverridesApiTest, ShouldCleanUpDuplicateEntries) {
123 // Simulate several LoadExtension() calls happening over the lifetime of 124 // Simulate several LoadExtension() calls happening over the lifetime of
124 // a preferences file without corresponding UnloadExtension() calls. This is 125 // a preferences file without corresponding UnloadExtension() calls. This is
125 // the same as the above test, except for that it is testing the case where 126 // the same as the above test, except for that it is testing the case where
126 // the file already contains dupes when an extension is loaded. 127 // the file already contains dupes when an extension is loaded.
127 ListValue* list = new ListValue(); 128 ListValue* list = new ListValue();
128 for (size_t i = 0; i < 3; ++i) 129 for (size_t i = 0; i < 3; ++i)
129 list->Append(Value::CreateStringValue("http://www.google.com/")); 130 list->Append(Value::CreateStringValue("http://www.google.com/"));
130 131
131 { 132 {
132 DictionaryPrefUpdate update(browser()->profile()->GetPrefs(), 133 DictionaryPrefUpdate update(browser()->profile()->GetPrefs(),
133 ExtensionWebUI::kExtensionURLOverrides); 134 ExtensionWebUI::kExtensionURLOverrides);
134 update.Get()->Set("history", list); 135 update.Get()->Set("history", list);
135 } 136 }
136 137
137 ASSERT_FALSE(CheckHistoryOverridesContainsNoDupes()); 138 ASSERT_FALSE(CheckHistoryOverridesContainsNoDupes());
138 139
139 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("override/history"))); 140 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("override/history")));
140 141
141 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes()); 142 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes());
142 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698