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

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

Powered by Google App Engine
This is Rietveld 408576698