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

Side by Side Diff: chrome/browser/extensions/api/extension_action/script_badge_apitest.cc

Issue 10823142: Fix a race condition when an IconAnimation is still running at browser shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 8 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/extensions/script_badge_controller.cc » ('j') | 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) 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/browser_event_router.h" 5 #include "chrome/browser/extensions/browser_event_router.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/extensions/location_bar_controller.h"
9 #include "chrome/browser/extensions/tab_helper.h"
8 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_tabstrip.h" 12 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_action.h" 16 #include "chrome/common/extensions/extension_action.h"
14 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "net/base/mock_host_resolver.h"
20 #include "net/test/test_server.h"
21 #include "testing/gmock/include/gmock/gmock.h"
16 22
17 using extensions::Extension; 23 using extensions::Extension;
18 24
19 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ScriptBadge) { 25 class ScriptBadgeApiTest : public ExtensionApiTest {
26 protected:
27 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
28 ExtensionApiTest::SetUpCommandLine(command_line);
29 command_line->AppendSwitch(switches::kEnableScriptBadges);
30 }
31 };
32
33 IN_PROC_BROWSER_TEST_F(ScriptBadgeApiTest, Basics) {
20 ASSERT_TRUE(test_server()->Start()); 34 ASSERT_TRUE(test_server()->Start());
21 ASSERT_TRUE(RunExtensionTest("script_badge/basics")) << message_; 35 ASSERT_TRUE(RunExtensionTest("script_badge/basics")) << message_;
22 const Extension* extension = GetSingleLoadedExtension(); 36 const Extension* extension = GetSingleLoadedExtension();
23 ASSERT_TRUE(extension) << message_; 37 ASSERT_TRUE(extension) << message_;
24 const ExtensionAction* script_badge = extension->script_badge(); 38 ExtensionAction* script_badge = extension->script_badge();
25 ASSERT_TRUE(script_badge); 39 ASSERT_TRUE(script_badge);
40 const extensions::LocationBarController* location_bar_controller =
41 chrome::GetActiveTabContents(browser())->extension_tab_helper()->
42 location_bar_controller();
26 43
27 const int tab_id = SessionID::IdForTab( 44 const int tab_id = SessionID::IdForTab(
28 chrome::GetActiveTabContents(browser())); 45 chrome::GetActiveTabContents(browser()));
29 EXPECT_EQ(GURL(extension->GetResourceURL("default_popup.html")), 46 EXPECT_EQ(GURL(extension->GetResourceURL("default_popup.html")),
30 script_badge->GetPopupUrl(tab_id)); 47 script_badge->GetPopupUrl(tab_id));
31 48
49 EXPECT_FALSE(script_badge->GetIsVisible(tab_id));
50 EXPECT_THAT(location_bar_controller->GetCurrentActions(),
51 testing::ElementsAre());
52
32 { 53 {
33 ResultCatcher catcher; 54 ResultCatcher catcher;
34 // Tell the extension to update the script badge state. 55 // Tell the extension to update the script badge state.
35 ui_test_utils::NavigateToURL( 56 ui_test_utils::NavigateToURL(
36 browser(), GURL(extension->GetResourceURL("update.html"))); 57 browser(), GURL(extension->GetResourceURL("update.html")));
37 ASSERT_TRUE(catcher.GetNextResult()); 58 ASSERT_TRUE(catcher.GetNextResult());
38 } 59 }
39 60
40 // Test that we received the changes. 61 // Test that we received the changes.
41 EXPECT_EQ(GURL(extension->GetResourceURL("set_popup.html")), 62 EXPECT_EQ(GURL(extension->GetResourceURL("set_popup.html")),
42 script_badge->GetPopupUrl(tab_id)); 63 script_badge->GetPopupUrl(tab_id));
43 64
44 { 65 {
45 // Simulate the script badge being clicked. 66 // Simulate the script badge being clicked.
46 ResultCatcher catcher; 67 ResultCatcher catcher;
47 ExtensionService* service = browser()->profile()->GetExtensionService(); 68 ExtensionService* service = browser()->profile()->GetExtensionService();
48 service->browser_event_router()->ScriptBadgeExecuted( 69 service->browser_event_router()->ScriptBadgeExecuted(
49 browser()->profile(), *script_badge, tab_id); 70 browser()->profile(), *script_badge, tab_id);
50 EXPECT_TRUE(catcher.GetNextResult()); 71 EXPECT_TRUE(catcher.GetNextResult());
51 } 72 }
73
74 {
75 ResultCatcher catcher;
76 // Visit a non-extension page so the extension can run a content script and
77 // cause the script badge to be animated in.
78 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(""));
79 ASSERT_TRUE(catcher.GetNextResult());
80 }
81 EXPECT_TRUE(script_badge->GetIsVisible(tab_id));
82 EXPECT_THAT(location_bar_controller->GetCurrentActions(),
83 testing::ElementsAre(script_badge));
52 } 84 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/script_badge_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698