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

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: ready to land 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/extension_tab_util.h"
13 #include "chrome/browser/extensions/script_bubble_controller.h"
14 #include "chrome/browser/extensions/test_extension_system.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_(FeatureSwitch::GetScriptBubble(), true) {
34 }
35
36 virtual void SetUp() OVERRIDE {
37 TabContentsTestHarness::SetUp();
38 CommandLine command_line(CommandLine::NO_PROGRAM);
39 extension_service_ =
40 static_cast<TestExtensionSystem*>(
41 ExtensionSystem::Get(tab_contents()->profile()))->
42 CreateExtensionService(
43 &command_line, FilePath(), false);
44 extension_service_->component_loader()->AddScriptBubble();
45 extension_service_->Init();
46
47 TabHelper::CreateForWebContents(web_contents());
48
49 script_bubble_controller_ =
50 TabHelper::FromWebContents(web_contents())->script_bubble_controller();
51 }
52
53 protected:
54 int tab_id() {
55 return ExtensionTabUtil::GetTabId(web_contents());
56 }
57
58 ExtensionService* extension_service_;
59 ScriptBubbleController* script_bubble_controller_;
60
61 private:
62 content::TestBrowserThread ui_thread_;
63 content::TestBrowserThread file_thread_;
64 FeatureSwitch::ScopedOverride enable_script_bubble_;
65 };
66
67 TEST_F(ScriptBubbleControllerTest, Basics) {
68 ExtensionAction* script_bubble_action =
69 extension_service_->component_loader()->GetScriptBubble()->
70 page_action();
71 ASSERT_TRUE(script_bubble_action);
72
73 // By default, the bubble should be invisible.
74 NavigateAndCommit(GURL("http://www.google.com"));
75 EXPECT_FALSE(script_bubble_action->GetIsVisible(tab_id()));
76 EXPECT_EQ("", script_bubble_action->GetBadgeText(tab_id()));
77
78 // Running a script on the tab causes the bubble to be visible.
79 TabHelper::ContentScriptObserver::ExecutingScriptsMap executing_scripts;
80 executing_scripts["id1"].insert("script1");
81 script_bubble_controller_->OnContentScriptsExecuting(
82 web_contents(),
83 executing_scripts,
84 web_contents()->GetController().GetActiveEntry()->GetPageID(),
85 web_contents()->GetController().GetActiveEntry()->GetURL());
86 EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id()));
87 EXPECT_EQ("1", script_bubble_action->GetBadgeText(tab_id()));
88
89 // Running a script from another extension increments the count.
90 executing_scripts["id2"].insert("script2");
91 script_bubble_controller_->OnContentScriptsExecuting(
92 web_contents(),
93 executing_scripts,
94 web_contents()->GetController().GetActiveEntry()->GetPageID(),
95 web_contents()->GetController().GetActiveEntry()->GetURL());
96 EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id()));
97 EXPECT_EQ("2", script_bubble_action->GetBadgeText(tab_id()));
98
99 // Running another script from an already-seen extension does not affect
100 // count.
101 executing_scripts["id2"].insert("script3");
102 script_bubble_controller_->OnContentScriptsExecuting(
103 web_contents(),
104 executing_scripts,
105 web_contents()->GetController().GetActiveEntry()->GetPageID(),
106 web_contents()->GetController().GetActiveEntry()->GetURL());
107 EXPECT_TRUE(script_bubble_action->GetIsVisible(tab_id()));
108 EXPECT_EQ("2", script_bubble_action->GetBadgeText(tab_id()));
109
110 // Navigating away resets the badge.
111 NavigateAndCommit(GURL("http://www.google.com"));
112 EXPECT_FALSE(script_bubble_action->GetIsVisible(tab_id()));
113 EXPECT_EQ("", script_bubble_action->GetBadgeText(tab_id()));
114 };
115
116 } // namespace
117 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/script_bubble_controller.cc ('k') | chrome/browser/extensions/tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698