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

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

Issue 11014009: Beginnings of the script bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More minor cleanup Created 8 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
10 #include "chrome/browser/extensions/component_loader.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/script_bubble_controller.h"
13 #include "chrome/browser/extensions/test_extension_system.h"
14 #include "chrome/browser/sessions/session_id.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents.h"
16 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/feature_switch.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/test/test_browser_thread.h"
22
23 using content::BrowserThread;
24
25 namespace extensions {
26 namespace {
27
28 class ScriptBubbleControllerTest : public TabContentsTestHarness {
29 public:
30 ScriptBubbleControllerTest()
31 : ui_thread_(BrowserThread::UI, MessageLoop::current()),
32 file_thread_(BrowserThread::FILE, MessageLoop::current()),
33 enable_script_bubble_(
34 FeatureSwitch::GetScriptBubble()->Override(true)) {
35 }
36
37 virtual void SetUp() OVERRIDE {
38 TabContentsTestHarness::SetUp();
39 CommandLine command_line(CommandLine::NO_PROGRAM);
40 extension_service_ =
41 static_cast<TestExtensionSystem*>(
42 ExtensionSystem::Get(tab_contents()->profile()))->
43 CreateExtensionService(
44 &command_line, FilePath(), false);
45 extension_service_->component_loader()->AddScriptBubble();
46 extension_service_->Init();
47
48 TabHelper::CreateForWebContents(web_contents());
49
50 script_bubble_controller_ =
51 TabHelper::FromWebContents(web_contents())->script_bubble_controller();
52 }
53
54 protected:
55 int tab_id() {
56 return SessionID::IdForTab(web_contents());
57 }
58
59 ExtensionService* extension_service_;
60 ScriptBubbleController* script_bubble_controller_;
61
62 private:
63 content::TestBrowserThread ui_thread_;
64 content::TestBrowserThread file_thread_;
65 FeatureSwitch::ScopedOverride enable_script_bubble_;
66 };
67
68 TEST_F(ScriptBubbleControllerTest, Basics) {
69 ExtensionAction* script_bubble_action =
70 extension_service_->component_loader()->GetScriptBubble()->
71 page_action();
72 ASSERT_TRUE(script_bubble_action);
73
74 // By default, the bubble should be invisible.
75 NavigateAndCommit(GURL("http://www.google.com"));
76 EXPECT_FALSE(script_bubble_action->GetIsVisible(tab_id()));
77 EXPECT_EQ("", script_bubble_action->GetBadgeText(tab_id()));
78
79 // Running a script on the tab causes the bubble to be visible.
80 TabHelper::ContentScriptObserver::ExecutingScriptsMap executing_scripts;
81 executing_scripts["id1"].insert("script1");
82 script_bubble_controller_->OnContentScriptsExecuting(
83 web_contents(),
84 executing_scripts,
85 web_contents()->GetController().GetActiveEntry()->GetPageID(),
86 web_contents()->GetController().GetActiveEntry()->GetURL());
87 EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id()));
88 EXPECT_EQ("1", script_bubble_action->GetBadgeText(tab_id()));
89
90 // Running a script from another extension increments the count.
91 executing_scripts["id2"].insert("script2");
92 script_bubble_controller_->OnContentScriptsExecuting(
93 web_contents(),
94 executing_scripts,
95 web_contents()->GetController().GetActiveEntry()->GetPageID(),
96 web_contents()->GetController().GetActiveEntry()->GetURL());
97 EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id()));
98 EXPECT_EQ("2", script_bubble_action->GetBadgeText(tab_id()));
99
100 // Running another script from an already-seen extension does not affect
101 // count.
102 executing_scripts["id2"].insert("script3");
103 script_bubble_controller_->OnContentScriptsExecuting(
104 web_contents(),
105 executing_scripts,
106 web_contents()->GetController().GetActiveEntry()->GetPageID(),
107 web_contents()->GetController().GetActiveEntry()->GetURL());
108 EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id()));
109 EXPECT_EQ("2", script_bubble_action->GetBadgeText(tab_id()));
110
111 // Navigating away resets the badge.
112 NavigateAndCommit(GURL("http://www.google.com"));
113 EXPECT_FALSE(script_bubble_action->GetIsVisible(tab_id()));
114 EXPECT_EQ("", script_bubble_action->GetBadgeText(tab_id()));
115 };
116
117 } // namespace
118 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698