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

Side by Side Diff: chrome/browser/extensions/all_urls_apitest.cc

Issue 1469813003: Revert of The AllUrlsApiTest.WhitelistedExtension test should no longer flake. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/test/base/test_switches.h" 10 #include "chrome/test/base/test_switches.h"
11 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
12 #include "components/crx_file/id_util.h" 12 #include "components/crx_file/id_util.h"
13 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
14 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
15 #include "extensions/common/extensions_client.h" 15 #include "extensions/common/extensions_client.h"
16 #include "extensions/test/extension_test_message_listener.h" 16 #include "extensions/test/extension_test_message_listener.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h" 17 #include "net/test/embedded_test_server/embedded_test_server.h"
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 namespace { 21 namespace {
22 const std::string kAllUrlsTarget = "/extensions/api_test/all_urls/index.html"; 22 const std::string kAllUrlsTarget = "/extensions/api_test/all_urls/index.html";
23 } 23 }
24 24
25 class AllUrlsApiTest : public ExtensionApiTest, 25 class AllUrlsApiTest : public ExtensionApiTest {
26 public ExtensionRegistryObserver {
27 protected: 26 protected:
28 AllUrlsApiTest() : wait_until_reload_(false), 27 AllUrlsApiTest() {}
29 content_script_is_reloaded_(false),
30 execute_script_is_reloaded_(false) {}
31 ~AllUrlsApiTest() override {} 28 ~AllUrlsApiTest() override {}
32 29
33 const Extension* content_script() const { return content_script_.get(); } 30 const Extension* content_script() const { return content_script_.get(); }
34 const Extension* execute_script() const { return execute_script_.get(); } 31 const Extension* execute_script() const { return execute_script_.get(); }
35 32
36 // ExtensionRegistryObserver implementation
37 void OnExtensionLoaded(
38 content::BrowserContext*,
39 const Extension* extension) override {
40 if (!wait_until_reload_)
41 return;
42
43 if (extension->id() == content_script_->id())
44 content_script_is_reloaded_ = true;
45 else if (extension->id() == execute_script_->id())
46 execute_script_is_reloaded_ = true;
47 if (content_script_is_reloaded_ && execute_script_is_reloaded_) {
48 base::MessageLoop::current()->QuitWhenIdle();
49 wait_until_reload_ = false;
50 }
51 }
52
53 void WhitelistExtensions() { 33 void WhitelistExtensions() {
54 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer(this);
55 observer.Add(ExtensionRegistry::Get(browser()->profile()));
56
57 ExtensionsClient::ScriptingWhitelist whitelist; 34 ExtensionsClient::ScriptingWhitelist whitelist;
58 whitelist.push_back(content_script_->id()); 35 whitelist.push_back(content_script_->id());
59 whitelist.push_back(execute_script_->id()); 36 whitelist.push_back(execute_script_->id());
60 ExtensionsClient::Get()->SetScriptingWhitelist(whitelist); 37 ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
61 // Extensions will have certain permissions withheld at initialization if 38 // Extensions will have certain permissions withheld at initialization if
62 // they aren't whitelisted, so we need to reload them. 39 // they aren't whitelisted, so we need to reload them.
63 content_script_is_reloaded_ = false;
64 execute_script_is_reloaded_ = false;
65 wait_until_reload_ = true;
66 extension_service()->ReloadExtension(content_script_->id()); 40 extension_service()->ReloadExtension(content_script_->id());
67 extension_service()->ReloadExtension(execute_script_->id()); 41 extension_service()->ReloadExtension(execute_script_->id());
68 base::MessageLoop::current()->Run();
69 } 42 }
70 43
71 private: 44 private:
72 void SetUpOnMainThread() override { 45 void SetUpOnMainThread() override {
73 ExtensionApiTest::SetUpOnMainThread(); 46 ExtensionApiTest::SetUpOnMainThread();
74 base::FilePath data_dir = test_data_dir_.AppendASCII("all_urls"); 47 base::FilePath data_dir = test_data_dir_.AppendASCII("all_urls");
75 content_script_ = LoadExtension(data_dir.AppendASCII("content_script")); 48 content_script_ = LoadExtension(data_dir.AppendASCII("content_script"));
76 ASSERT_TRUE(content_script_); 49 ASSERT_TRUE(content_script_);
77 execute_script_ = LoadExtension(data_dir.AppendASCII("execute_script")); 50 execute_script_ = LoadExtension(data_dir.AppendASCII("execute_script"));
78 ASSERT_TRUE(execute_script_); 51 ASSERT_TRUE(execute_script_);
79 } 52 }
80 53
81 scoped_refptr<const Extension> content_script_; 54 scoped_refptr<const Extension> content_script_;
82 scoped_refptr<const Extension> execute_script_; 55 scoped_refptr<const Extension> execute_script_;
83 56
84 bool wait_until_reload_;
85 bool content_script_is_reloaded_;
86 bool execute_script_is_reloaded_;
87
88 DISALLOW_COPY_AND_ASSIGN(AllUrlsApiTest); 57 DISALLOW_COPY_AND_ASSIGN(AllUrlsApiTest);
89 }; 58 };
90 59
91 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, WhitelistedExtension) { 60 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_CHROMEOS) || \
61 (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER))
62 // http://crbug.com/174341
63 #define MAYBE_WhitelistedExtension DISABLED_WhitelistedExtension
64 #else
65 #define MAYBE_WhitelistedExtension WhitelistedExtension
66 #endif
67 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, MAYBE_WhitelistedExtension) {
92 #if defined(OS_WIN) && defined(USE_ASH) 68 #if defined(OS_WIN) && defined(USE_ASH)
93 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 69 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
94 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 70 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
95 switches::kAshBrowserTests)) 71 switches::kAshBrowserTests))
96 return; 72 return;
97 #endif 73 #endif
98 74
99 WhitelistExtensions(); 75 WhitelistExtensions();
100 76
101 std::string url; 77 std::string url;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 GURL page_url = embedded_test_server()->GetURL(kAllUrlsTarget); 127 GURL page_url = embedded_test_server()->GetURL(kAllUrlsTarget);
152 ExtensionTestMessageListener listener1a("content script: " + page_url.spec(), 128 ExtensionTestMessageListener listener1a("content script: " + page_url.spec(),
153 false); 129 false);
154 ExtensionTestMessageListener listener1b("execute: " + page_url.spec(), false); 130 ExtensionTestMessageListener listener1b("execute: " + page_url.spec(), false);
155 ui_test_utils::NavigateToURL(browser(), page_url); 131 ui_test_utils::NavigateToURL(browser(), page_url);
156 ASSERT_TRUE(listener1a.WaitUntilSatisfied()); 132 ASSERT_TRUE(listener1a.WaitUntilSatisfied());
157 ASSERT_TRUE(listener1b.WaitUntilSatisfied()); 133 ASSERT_TRUE(listener1b.WaitUntilSatisfied());
158 } 134 }
159 135
160 // Disabled because sometimes bystander doesn't load. 136 // Disabled because sometimes bystander doesn't load.
137 // TODO(devlin): Why?
161 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, 138 IN_PROC_BROWSER_TEST_F(AllUrlsApiTest,
162 WhitelistedExtensionRunsOnExtensionPages) { 139 DISABLED_WhitelistedExtensionRunsOnExtensionPages) {
163 WhitelistExtensions(); 140 WhitelistExtensions();
164 const Extension* bystander = 141 const Extension* bystander =
165 LoadExtension(test_data_dir_.AppendASCII("all_urls") 142 LoadExtension(test_data_dir_.AppendASCII("all_urls")
166 .AppendASCII("bystander")); 143 .AppendASCII("bystander"));
167 ASSERT_TRUE(bystander); 144 ASSERT_TRUE(bystander);
168 145
146 // TODO(devlin): This test should probably go in the WhitelistedExtension test
147 // above, but that one has a bunch of disableds, so it wouldn't be very
148 // useful.
169 GURL url(bystander->GetResourceURL("page.html")); 149 GURL url(bystander->GetResourceURL("page.html"));
170 ExtensionTestMessageListener listenerA( 150 ExtensionTestMessageListener listenerA(
171 "content script: " + url.spec(), false); 151 "content script: " + url.spec(), false);
172 ExtensionTestMessageListener listenerB("execute: " + url.spec(), false); 152 ExtensionTestMessageListener listenerB("execute: " + url.spec(), false);
173 ui_test_utils::NavigateToURL(browser(), GURL(url)); 153 ui_test_utils::NavigateToURL(browser(), GURL(url));
174 ASSERT_TRUE(listenerA.WaitUntilSatisfied()); 154 ASSERT_TRUE(listenerA.WaitUntilSatisfied());
175 ASSERT_TRUE(listenerB.WaitUntilSatisfied()); 155 ASSERT_TRUE(listenerB.WaitUntilSatisfied());
176 } 156 }
177 157
178 } // namespace extensions 158 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698