| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 | 33 |
| 34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
| 36 #include "chrome/browser/chromeos/settings/cros_settings.h" | 36 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 37 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 37 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 using content::BrowserThread; | |
| 41 | |
| 42 namespace extensions { | 40 namespace extensions { |
| 43 namespace { | 41 namespace { |
| 44 | 42 |
| 45 class ScriptBadgeControllerTest : public ChromeRenderViewHostTestHarness { | 43 class ScriptBadgeControllerTest : public ChromeRenderViewHostTestHarness { |
| 46 public: | 44 public: |
| 47 ScriptBadgeControllerTest() | 45 ScriptBadgeControllerTest() |
| 48 : feature_override_(FeatureSwitch::script_badges(), true), | 46 : feature_override_(FeatureSwitch::script_badges(), true), |
| 49 ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | |
| 50 file_thread_(BrowserThread::FILE, base::MessageLoop::current()), | |
| 51 current_channel_(chrome::VersionInfo::CHANNEL_DEV) {} | 47 current_channel_(chrome::VersionInfo::CHANNEL_DEV) {} |
| 52 | 48 |
| 53 virtual void SetUp() OVERRIDE { | 49 virtual void SetUp() OVERRIDE { |
| 54 // Note that this sets a PageActionController into the | 50 // Note that this sets a PageActionController into the |
| 55 // extensions::TabHelper's location_bar_controller field. Do | 51 // extensions::TabHelper's location_bar_controller field. Do |
| 56 // not use that for testing. | 52 // not use that for testing. |
| 57 ChromeRenderViewHostTestHarness::SetUp(); | 53 ChromeRenderViewHostTestHarness::SetUp(); |
| 58 | 54 |
| 55 #if defined OS_CHROMEOS |
| 56 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 57 #endif |
| 58 |
| 59 Profile* profile = | 59 Profile* profile = |
| 60 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 60 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 61 TestExtensionSystem* extension_system = | 61 TestExtensionSystem* extension_system = |
| 62 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile)); | 62 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile)); |
| 63 | 63 |
| 64 // Create an ExtensionService so the ScriptBadgeController can find its | 64 // Create an ExtensionService so the ScriptBadgeController can find its |
| 65 // extensions. | 65 // extensions. |
| 66 CommandLine command_line(CommandLine::NO_PROGRAM); | 66 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 67 extension_service_ = extension_system->CreateExtensionService( | 67 extension_service_ = extension_system->CreateExtensionService( |
| 68 &command_line, base::FilePath(), false); | 68 &command_line, base::FilePath(), false); |
| 69 | 69 |
| 70 TabHelper::CreateForWebContents(web_contents()); | 70 TabHelper::CreateForWebContents(web_contents()); |
| 71 script_badge_controller_ = static_cast<ScriptBadgeController*>( | 71 script_badge_controller_ = static_cast<ScriptBadgeController*>( |
| 72 TabHelper::FromWebContents(web_contents())->location_bar_controller()); | 72 TabHelper::FromWebContents(web_contents())->location_bar_controller()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void TearDown() OVERRIDE { |
| 76 #if defined OS_CHROMEOS |
| 77 test_user_manager_.reset(); |
| 78 #endif |
| 79 ChromeRenderViewHostTestHarness::TearDown(); |
| 80 } |
| 81 |
| 75 protected: | 82 protected: |
| 76 // Creates a test extension and adds it to |extension_service_|. | 83 // Creates a test extension and adds it to |extension_service_|. |
| 77 scoped_refptr<const Extension> AddTestExtension() { | 84 scoped_refptr<const Extension> AddTestExtension() { |
| 78 scoped_refptr<const Extension> extension = ExtensionBuilder() | 85 scoped_refptr<const Extension> extension = ExtensionBuilder() |
| 79 .SetManifest(DictionaryBuilder() | 86 .SetManifest(DictionaryBuilder() |
| 80 .Set("name", "Extension with page action") | 87 .Set("name", "Extension with page action") |
| 81 .Set("version", "1.0.0") | 88 .Set("version", "1.0.0") |
| 82 .Set("manifest_version", 2) | 89 .Set("manifest_version", 2) |
| 83 .Set("permissions", ListBuilder() | 90 .Set("permissions", ListBuilder() |
| 84 .Append("tabs")) | 91 .Append("tabs")) |
| 85 .Set("page_action", DictionaryBuilder() | 92 .Set("page_action", DictionaryBuilder() |
| 86 .Set("default_title", "Hello"))) | 93 .Set("default_title", "Hello"))) |
| 87 .Build(); | 94 .Build(); |
| 88 extension_service_->AddExtension(extension.get()); | 95 extension_service_->AddExtension(extension.get()); |
| 89 return extension; | 96 return extension; |
| 90 } | 97 } |
| 91 | 98 |
| 92 ExtensionAction* GetScriptBadge(const Extension& extension) { | 99 ExtensionAction* GetScriptBadge(const Extension& extension) { |
| 93 return ExtensionActionManager::Get(profile())->GetScriptBadge(extension); | 100 return ExtensionActionManager::Get(profile())->GetScriptBadge(extension); |
| 94 } | 101 } |
| 95 | 102 |
| 96 ExtensionService* extension_service_; | 103 ExtensionService* extension_service_; |
| 97 ScriptBadgeController* script_badge_controller_; | 104 ScriptBadgeController* script_badge_controller_; |
| 98 | 105 |
| 99 private: | 106 private: |
| 100 FeatureSwitch::ScopedOverride feature_override_; | 107 FeatureSwitch::ScopedOverride feature_override_; |
| 101 content::TestBrowserThread ui_thread_; | |
| 102 content::TestBrowserThread file_thread_; | |
| 103 Feature::ScopedCurrentChannel current_channel_; | 108 Feature::ScopedCurrentChannel current_channel_; |
| 104 | 109 |
| 105 #if defined OS_CHROMEOS | 110 #if defined OS_CHROMEOS |
| 106 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 111 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 107 chromeos::ScopedTestCrosSettings test_cros_settings_; | 112 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 108 chromeos::ScopedTestUserManager test_user_manager_; | 113 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 109 #endif | 114 #endif |
| 110 }; | 115 }; |
| 111 | 116 |
| 112 struct CountingNotificationObserver : public content::NotificationObserver { | 117 struct CountingNotificationObserver : public content::NotificationObserver { |
| 113 CountingNotificationObserver() : events(0) {} | 118 CountingNotificationObserver() : events(0) {} |
| 114 | 119 |
| 115 virtual void Observe(int type, | 120 virtual void Observe(int type, |
| 116 const content::NotificationSource& source, | 121 const content::NotificationSource& source, |
| 117 const content::NotificationDetails& details) OVERRIDE { | 122 const content::NotificationDetails& details) OVERRIDE { |
| 118 events++; | 123 events++; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // Getting attention a second time should have no effect. | 268 // Getting attention a second time should have no effect. |
| 264 script_badge_controller_->GetAttentionFor(extension->id()); | 269 script_badge_controller_->GetAttentionFor(extension->id()); |
| 265 | 270 |
| 266 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), | 271 EXPECT_THAT(script_badge_controller_->GetCurrentActions(), |
| 267 testing::ElementsAre(GetScriptBadge(*extension.get()))); | 272 testing::ElementsAre(GetScriptBadge(*extension.get()))); |
| 268 EXPECT_EQ(0, subsequent_get_attention_call.events); | 273 EXPECT_EQ(0, subsequent_get_attention_call.events); |
| 269 }; | 274 }; |
| 270 | 275 |
| 271 } // namespace | 276 } // namespace |
| 272 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |