| OLD | NEW |
| 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_action.h" | 6 #include "chrome/browser/extensions/extension_action.h" |
| 7 #include "chrome/browser/extensions/extension_action_manager.h" | 7 #include "chrome/browser/extensions/extension_action_manager.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/location_bar_controller.h" | 11 #include "chrome/browser/extensions/location_bar_controller.h" |
| 12 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/features/feature.h" | 18 #include "chrome/common/extensions/features/feature.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/test/spawned_test_server/spawned_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class ScriptBadgeApiTest : public ExtensionApiTest { | 28 class ScriptBadgeApiTest : public ExtensionApiTest { |
| 29 public: | 29 public: |
| 30 ScriptBadgeApiTest() : trunk_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} | 30 ScriptBadgeApiTest() : trunk_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 34 ExtensionApiTest::SetUpCommandLine(command_line); | 34 ExtensionApiTest::SetUpCommandLine(command_line); |
| 35 command_line->AppendSwitchASCII(switches::kScriptBadges, "1"); | 35 command_line->AppendSwitchASCII(switches::kScriptBadges, "1"); |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 extensions::Feature::ScopedCurrentChannel trunk_; | 39 extensions::Feature::ScopedCurrentChannel trunk_; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 IN_PROC_BROWSER_TEST_F(ScriptBadgeApiTest, Basics) { | 42 IN_PROC_BROWSER_TEST_F(ScriptBadgeApiTest, Basics) { |
| 43 ASSERT_TRUE(test_server()->Start()); | 43 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 44 ASSERT_TRUE(RunExtensionTest("script_badge/basics")) << message_; | 44 ASSERT_TRUE(RunExtensionTest("script_badge/basics")) << message_; |
| 45 const Extension* extension = GetSingleLoadedExtension(); | 45 const Extension* extension = GetSingleLoadedExtension(); |
| 46 ASSERT_TRUE(extension) << message_; | 46 ASSERT_TRUE(extension) << message_; |
| 47 ExtensionAction* script_badge = | 47 ExtensionAction* script_badge = |
| 48 ExtensionActionManager::Get(browser()->profile())-> | 48 ExtensionActionManager::Get(browser()->profile())-> |
| 49 GetScriptBadge(*extension); | 49 GetScriptBadge(*extension); |
| 50 ASSERT_TRUE(script_badge); | 50 ASSERT_TRUE(script_badge); |
| 51 const extensions::LocationBarController* location_bar_controller = | 51 const extensions::LocationBarController* location_bar_controller = |
| 52 extensions::TabHelper::FromWebContents( | 52 extensions::TabHelper::FromWebContents( |
| 53 browser()->tab_strip_model()->GetActiveWebContents())-> | 53 browser()->tab_strip_model()->GetActiveWebContents())-> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 81 browser()->profile())->extension_service(); | 81 browser()->profile())->extension_service(); |
| 82 service->browser_event_router()->ScriptBadgeExecuted( | 82 service->browser_event_router()->ScriptBadgeExecuted( |
| 83 browser()->profile(), *script_badge, tab_id); | 83 browser()->profile(), *script_badge, tab_id); |
| 84 EXPECT_TRUE(catcher.GetNextResult()); | 84 EXPECT_TRUE(catcher.GetNextResult()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 { | 87 { |
| 88 ResultCatcher catcher; | 88 ResultCatcher catcher; |
| 89 // Visit a non-extension page so the extension can run a content script and | 89 // Visit a non-extension page so the extension can run a content script and |
| 90 // cause the script badge to be animated in. | 90 // cause the script badge to be animated in. |
| 91 ui_test_utils::NavigateToURL(browser(), | 91 ui_test_utils::NavigateToURL( |
| 92 test_server()->GetURL(std::string())); | 92 browser(), embedded_test_server()->GetURL("/title1.html")); |
| 93 ASSERT_TRUE(catcher.GetNextResult()); | 93 ASSERT_TRUE(catcher.GetNextResult()); |
| 94 } | 94 } |
| 95 EXPECT_TRUE(script_badge->GetIsVisible(tab_id)); | 95 EXPECT_TRUE(script_badge->GetIsVisible(tab_id)); |
| 96 EXPECT_THAT(location_bar_controller->GetCurrentActions(), | 96 EXPECT_THAT(location_bar_controller->GetCurrentActions(), |
| 97 testing::ElementsAre(script_badge)); | 97 testing::ElementsAre(script_badge)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 } // namespace extensions | 101 } // namespace extensions |
| OLD | NEW |