| 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/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
| 42 ChromeRenderViewHostTestHarness::SetUp(); | 42 ChromeRenderViewHostTestHarness::SetUp(); |
| 43 CommandLine command_line(CommandLine::NO_PROGRAM); | 43 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 44 Profile* profile = | 44 Profile* profile = |
| 45 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 45 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 46 extension_service_ = static_cast<TestExtensionSystem*>( | 46 extension_service_ = static_cast<TestExtensionSystem*>( |
| 47 ExtensionSystem::Get(profile))->CreateExtensionService( | 47 ExtensionSystem::Get(profile))->CreateExtensionService( |
| 48 &command_line, FilePath(), false); | 48 &command_line, FilePath(), false); |
| 49 extension_service_->component_loader()->AddScriptBubble(); | |
| 50 extension_service_->Init(); | 49 extension_service_->Init(); |
| 51 | 50 |
| 52 TabHelper::CreateForWebContents(web_contents()); | 51 TabHelper::CreateForWebContents(web_contents()); |
| 53 | 52 |
| 54 script_bubble_controller_ = | 53 script_bubble_controller_ = |
| 55 TabHelper::FromWebContents(web_contents())->script_bubble_controller(); | 54 TabHelper::FromWebContents(web_contents())->script_bubble_controller(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 protected: | 57 protected: |
| 59 int tab_id() { | 58 int tab_id() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 .SetManifest(DictionaryBuilder() | 98 .SetManifest(DictionaryBuilder() |
| 100 .Set("name", "ex3") | 99 .Set("name", "ex3") |
| 101 .Set("version", "1") | 100 .Set("version", "1") |
| 102 .Set("manifest_version", 2)) | 101 .Set("manifest_version", 2)) |
| 103 .Build(); | 102 .Build(); |
| 104 | 103 |
| 105 extension_service_->AddExtension(extension1); | 104 extension_service_->AddExtension(extension1); |
| 106 extension_service_->AddExtension(extension2); | 105 extension_service_->AddExtension(extension2); |
| 107 extension_service_->AddExtension(extension3); | 106 extension_service_->AddExtension(extension3); |
| 108 | 107 |
| 109 const Extension* script_bubble = | 108 EXPECT_EQ(0u, script_bubble_controller_->extensions_running_scripts().size()); |
| 110 extension_service_->component_loader()->GetScriptBubble(); | |
| 111 ExtensionAction* script_bubble_action = | |
| 112 ExtensionActionManager::Get(profile())->GetPageAction(*script_bubble); | |
| 113 ASSERT_TRUE(script_bubble_action); | |
| 114 | 109 |
| 115 // By default, the bubble should be invisible. | |
| 116 NavigateAndCommit(GURL("http://www.google.com")); | 110 NavigateAndCommit(GURL("http://www.google.com")); |
| 117 EXPECT_FALSE(script_bubble_action->GetIsVisible(tab_id())); | |
| 118 EXPECT_EQ("", script_bubble_action->GetBadgeText(tab_id())); | |
| 119 EXPECT_EQ(0u, script_bubble_controller_->extensions_running_scripts().size()); | |
| 120 | 111 |
| 121 // Running a script on the tab causes the bubble to be visible. | 112 // Running a script on the tab causes the bubble to be visible. |
| 122 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap executing_scripts; | 113 TabHelper::ScriptExecutionObserver::ExecutingScriptsMap executing_scripts; |
| 123 executing_scripts[extension1->id()].insert("script1"); | 114 executing_scripts[extension1->id()].insert("script1"); |
| 124 script_bubble_controller_->OnScriptsExecuted( | 115 script_bubble_controller_->OnScriptsExecuted( |
| 125 web_contents(), | 116 web_contents(), |
| 126 executing_scripts, | 117 executing_scripts, |
| 127 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 118 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
| 128 web_contents()->GetController().GetActiveEntry()->GetURL()); | 119 web_contents()->GetController().GetActiveEntry()->GetURL()); |
| 129 // TODO(finnur): Figure out visibility test. | |
| 130 // EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id())); | |
| 131 EXPECT_EQ(1u, script_bubble_controller_->extensions_running_scripts().size()); | 120 EXPECT_EQ(1u, script_bubble_controller_->extensions_running_scripts().size()); |
| 132 std::set<std::string> extension_ids; | 121 std::set<std::string> extension_ids; |
| 133 extension_ids.insert(extension1->id()); | 122 extension_ids.insert(extension1->id()); |
| 134 EXPECT_EQ(1u, script_bubble_controller_->extensions_running_scripts().size()); | 123 EXPECT_EQ(1u, script_bubble_controller_->extensions_running_scripts().size()); |
| 135 EXPECT_TRUE(extension_ids == | 124 EXPECT_TRUE(extension_ids == |
| 136 script_bubble_controller_->extensions_running_scripts()); | 125 script_bubble_controller_->extensions_running_scripts()); |
| 137 | 126 |
| 138 // Running a script from another extension increments the count. | 127 // Running a script from another extension increments the count. |
| 139 executing_scripts.clear(); | 128 executing_scripts.clear(); |
| 140 executing_scripts[extension2->id()].insert("script2"); | 129 executing_scripts[extension2->id()].insert("script2"); |
| 141 script_bubble_controller_->OnScriptsExecuted( | 130 script_bubble_controller_->OnScriptsExecuted( |
| 142 web_contents(), | 131 web_contents(), |
| 143 executing_scripts, | 132 executing_scripts, |
| 144 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 133 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
| 145 web_contents()->GetController().GetActiveEntry()->GetURL()); | 134 web_contents()->GetController().GetActiveEntry()->GetURL()); |
| 146 // EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id())); | |
| 147 EXPECT_EQ(2u, script_bubble_controller_->extensions_running_scripts().size()); | 135 EXPECT_EQ(2u, script_bubble_controller_->extensions_running_scripts().size()); |
| 148 extension_ids.insert(extension2->id()); | 136 extension_ids.insert(extension2->id()); |
| 149 EXPECT_TRUE(extension_ids == | 137 EXPECT_TRUE(extension_ids == |
| 150 script_bubble_controller_->extensions_running_scripts()); | 138 script_bubble_controller_->extensions_running_scripts()); |
| 151 | 139 |
| 152 // Running another script from an already-seen extension does not affect | 140 // Running another script from an already-seen extension does not affect |
| 153 // count. | 141 // count. |
| 154 executing_scripts.clear(); | 142 executing_scripts.clear(); |
| 155 executing_scripts[extension2->id()].insert("script3"); | 143 executing_scripts[extension2->id()].insert("script3"); |
| 156 script_bubble_controller_->OnScriptsExecuted( | 144 script_bubble_controller_->OnScriptsExecuted( |
| 157 web_contents(), | 145 web_contents(), |
| 158 executing_scripts, | 146 executing_scripts, |
| 159 web_contents()->GetController().GetActiveEntry()->GetPageID(), | 147 web_contents()->GetController().GetActiveEntry()->GetPageID(), |
| 160 web_contents()->GetController().GetActiveEntry()->GetURL()); | 148 web_contents()->GetController().GetActiveEntry()->GetURL()); |
| 161 // EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id())); | |
| 162 EXPECT_EQ(2u, script_bubble_controller_->extensions_running_scripts().size()); | 149 EXPECT_EQ(2u, script_bubble_controller_->extensions_running_scripts().size()); |
| 163 | 150 |
| 164 // Running tabs.executeScript from an already-seen extension does not affect | 151 // Running tabs.executeScript from an already-seen extension does not affect |
| 165 // count. | 152 // count. |
| 166 executing_scripts.clear(); | 153 executing_scripts.clear(); |
| 167 executing_scripts[extension1->id()] = std::set<std::string>(); | 154 executing_scripts[extension1->id()] = std::set<std::string>(); |
| 168 script_bubble_controller_->OnScriptsExecuted( | 155 script_bubble_controller_->OnScriptsExecuted( |
| 169 web_contents(), executing_scripts, 0, GURL()); | 156 web_contents(), executing_scripts, 0, GURL()); |
| 170 // EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id())); | |
| 171 EXPECT_EQ(2u, script_bubble_controller_->extensions_running_scripts().size()); | 157 EXPECT_EQ(2u, script_bubble_controller_->extensions_running_scripts().size()); |
| 172 | 158 |
| 173 // Running tabs.executeScript from a new extension increments the count. | 159 // Running tabs.executeScript from a new extension increments the count. |
| 174 executing_scripts.clear(); | 160 executing_scripts.clear(); |
| 175 executing_scripts[extension3->id()] = std::set<std::string>(); | 161 executing_scripts[extension3->id()] = std::set<std::string>(); |
| 176 script_bubble_controller_->OnScriptsExecuted( | 162 script_bubble_controller_->OnScriptsExecuted( |
| 177 web_contents(), executing_scripts, 0, GURL()); | 163 web_contents(), executing_scripts, 0, GURL()); |
| 178 // EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id())); | |
| 179 extension_ids.insert(extension3->id()); | |
| 180 EXPECT_EQ(3u, script_bubble_controller_->extensions_running_scripts().size()); | 164 EXPECT_EQ(3u, script_bubble_controller_->extensions_running_scripts().size()); |
| 181 | 165 |
| 182 // Navigating away resets the badge. | 166 // Navigating away resets the badge. |
| 183 NavigateAndCommit(GURL("http://www.google.com")); | 167 NavigateAndCommit(GURL("http://www.google.com")); |
| 184 EXPECT_FALSE(script_bubble_action->GetIsVisible(tab_id())); | 168 EXPECT_EQ(0u, script_bubble_controller_->extensions_running_scripts().size()); |
| 185 EXPECT_EQ("", script_bubble_action->GetBadgeText(tab_id())); | |
| 186 }; | 169 }; |
| 187 | 170 |
| 188 } // namespace | 171 } // namespace |
| 189 } // namespace extensions | 172 } // namespace extensions |
| OLD | NEW |