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

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

Issue 16268017: GTTF: convert some tests in chrome to use EmbeddedTestServer patch nr 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready? Created 7 years, 6 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 | Annotate | Revision Log
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "chrome/browser/bookmarks/bookmark_utils.h" 10 #include "chrome/browser/bookmarks/bookmark_utils.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/test/browser_test_utils.h" 30 #include "content/public/test/browser_test_utils.h"
31 #include "googleurl/src/gurl.h" 31 #include "googleurl/src/gurl.h"
32 #include "net/dns/mock_host_resolver.h" 32 #include "net/dns/mock_host_resolver.h"
33 #include "net/test/embedded_test_server/embedded_test_server.h"
33 34
34 using extensions::Extension; 35 using extensions::Extension;
35 36
36 namespace { 37 namespace {
37 38
38 // This unfortunate bit of silliness is necessary when loading an extension in 39 // This unfortunate bit of silliness is necessary when loading an extension in
39 // incognito. The goal is to load the extension, enable incognito, then wait 40 // incognito. The goal is to load the extension, enable incognito, then wait
40 // for both background pages to load and close. The problem is that enabling 41 // for both background pages to load and close. The problem is that enabling
41 // incognito involves reloading the extension - and the background pages may 42 // incognito involves reloading the extension - and the background pages may
42 // have already loaded once before then. So we wait until the extension is 43 // have already loaded once before then. So we wait until the extension is
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 153 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
153 int num_page_actions = browser()->window()->GetLocationBar()-> 154 int num_page_actions = browser()->window()->GetLocationBar()->
154 GetLocationBarForTesting()->PageActionVisibleCount(); 155 GetLocationBarForTesting()->PageActionVisibleCount();
155 156
156 // Open a tab to a URL that will trigger the page action to show. 157 // Open a tab to a URL that will trigger the page action to show.
157 LazyBackgroundObserver page_complete; 158 LazyBackgroundObserver page_complete;
158 content::WindowedNotificationObserver page_action_changed( 159 content::WindowedNotificationObserver page_action_changed(
159 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 160 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
160 content::NotificationService::AllSources()); 161 content::NotificationService::AllSources());
161 ui_test_utils::NavigateToURL( 162 ui_test_utils::NavigateToURL(
162 browser(), test_server()->GetURL("files/extensions/test_file.html")); 163 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
163 page_complete.Wait(); 164 page_complete.Wait();
164 165
165 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 166 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
166 167
167 // Page action is shown. 168 // Page action is shown.
168 page_action_changed.Wait(); 169 page_action_changed.Wait();
169 EXPECT_EQ(num_page_actions + 1, 170 EXPECT_EQ(num_page_actions + 1,
170 browser()->window()->GetLocationBar()-> 171 browser()->window()->GetLocationBar()->
171 GetLocationBarForTesting()->PageActionVisibleCount()); 172 GetLocationBarForTesting()->PageActionVisibleCount());
172 } 173 }
173 174
174 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) { 175 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) {
175 const Extension* extension = LoadExtensionAndWait("filters"); 176 const Extension* extension = LoadExtensionAndWait("filters");
176 ASSERT_TRUE(extension); 177 ASSERT_TRUE(extension);
177 178
178 // Lazy Background Page doesn't exist yet. 179 // Lazy Background Page doesn't exist yet.
179 ExtensionProcessManager* pm = 180 ExtensionProcessManager* pm =
180 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 181 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
181 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 182 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
182 183
183 // Open a tab to a URL that will fire a webNavigation event. 184 // Open a tab to a URL that will fire a webNavigation event.
184 LazyBackgroundObserver page_complete; 185 LazyBackgroundObserver page_complete;
185 ui_test_utils::NavigateToURL( 186 ui_test_utils::NavigateToURL(
186 browser(), test_server()->GetURL("files/extensions/test_file.html")); 187 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
187 page_complete.Wait(); 188 page_complete.Wait();
188 } 189 }
189 190
190 // Tests that the lazy background page receives the onInstalled event and shuts 191 // Tests that the lazy background page receives the onInstalled event and shuts
191 // down. 192 // down.
192 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) { 193 IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) {
193 ResultCatcher catcher; 194 ResultCatcher catcher;
194 ASSERT_TRUE(LoadExtensionAndWait("on_installed")); 195 ASSERT_TRUE(LoadExtensionAndWait("on_installed"));
195 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 196 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
196 197
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // Lazy Background Page doesn't exist yet. 383 // Lazy Background Page doesn't exist yet.
383 ExtensionProcessManager* pm = 384 ExtensionProcessManager* pm =
384 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 385 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
385 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 386 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
386 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 387 EXPECT_EQ(1, browser()->tab_strip_model()->count());
387 388
388 // Navigate to a page that opens a message channel to the background page. 389 // Navigate to a page that opens a message channel to the background page.
389 ResultCatcher catcher; 390 ResultCatcher catcher;
390 LazyBackgroundObserver lazybg; 391 LazyBackgroundObserver lazybg;
391 ui_test_utils::NavigateToURL( 392 ui_test_utils::NavigateToURL(
392 browser(), test_server()->GetURL("files/extensions/test_file.html")); 393 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
393 lazybg.WaitUntilLoaded(); 394 lazybg.WaitUntilLoaded();
394 395
395 // Background page got the content script's message and is still loaded 396 // Background page got the content script's message and is still loaded
396 // until we close the channel. 397 // until we close the channel.
397 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 398 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
398 EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 399 EXPECT_TRUE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
399 400
400 // Navigate away, closing the message channel and therefore the background 401 // Navigate away, closing the message channel and therefore the background
401 // page. 402 // page.
402 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 403 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 454
454 EXPECT_TRUE(event_page_ready.WaitUntilSatisfied()); 455 EXPECT_TRUE(event_page_ready.WaitUntilSatisfied());
455 456
456 page_ready.Reply("go"); 457 page_ready.Reply("go");
457 458
458 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 459 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
459 } 460 }
460 461
461 // TODO: background page with timer. 462 // TODO: background page with timer.
462 // TODO: background page that interacts with popup. 463 // TODO: background page that interacts with popup.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698