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

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

Issue 1168383002: Implement sidebar support for extension action popups Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix assertion failure at extension_view_host.cc Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "chrome/browser/extensions/browser_action_test_util.h"
6 #include "chrome/browser/extensions/extension_action_manager.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "extensions/common/extension.h"
16
17 namespace extensions {
18
19 class SidebarBrowserTest : public ExtensionBrowserTest {
20 public:
21 SidebarBrowserTest() {}
22 ~SidebarBrowserTest() override {}
23
24 protected:
25 // InProcessBrowserTest
26 void SetUpOnMainThread() override {
27 ExtensionBrowserTest::SetUpOnMainThread();
28
29 // Load test sidebar extensions
30 firstExtension_ = LoadExtension(test_data_dir_.AppendASCII("sidebar"));
31 ASSERT_TRUE(firstExtension_);
32
33 secondExtension_ = LoadExtension(test_data_dir_.AppendASCII("sidebar2"));
34 ASSERT_TRUE(secondExtension_);
35
36 ASSERT_NE(firstExtension_->id(), secondExtension_->id());
37
38 browser_action_test_util_.reset(new BrowserActionTestUtil(browser()));
39 }
40
41 const ExtensionId first_extension_id() { return firstExtension_->id(); }
42
43 const ExtensionId second_extension_id() { return secondExtension_->id(); }
44
45 void ClickExtensionBrowserAction() {
46 browser_action_test_util_.get()->Press(0);
47 }
48
49 ToolbarActionsBar* toolbar_actions_bar() {
50 return browser_action_test_util_->GetToolbarActionsBar();
51 }
52
53 ExtensionAction* GetBrowserAction(const Extension& extension) {
54 return ExtensionActionManager::Get(browser()->profile())
55 ->GetBrowserAction(extension);
56 }
57
58 void DisableOpenInSidebar() {
59 GetBrowserAction(*firstExtension_)->set_open_in_sidebar(false);
60 GetBrowserAction(*secondExtension_)->set_open_in_sidebar(false);
61 }
62
63 bool IsShowingSidebar(const ExtensionId id) {
64 ExtensionActionViewController* controller;
65 for (unsigned int i = 0; i < toolbar_actions_bar()->GetActions().size();
66 i++) {
67 controller = static_cast<ExtensionActionViewController*>(
68 toolbar_actions_bar()->GetActions()[i]);
69 if (controller->extension()->id() == id) {
70 return controller->is_showing_sidebar();
71 }
72 }
73 return false;
74 }
75
76 void ClickBrowserAction(const ExtensionId id) {
77 ExtensionActionViewController* controller;
78 for (unsigned int i = 0; i < toolbar_actions_bar()->GetActions().size();
79 i++) {
80 controller = static_cast<ExtensionActionViewController*>(
81 toolbar_actions_bar()->GetActions()[i]);
82 if (controller->extension()->id() == id) {
83 browser_action_test_util_.get()->Press(i);
84 }
85 }
86 }
87
88 private:
89 const Extension* firstExtension_;
90 const Extension* secondExtension_;
91 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
92 };
93
94 // 1 - Tests that cliking on the browser action show/hides the sidebar
95 IN_PROC_BROWSER_TEST_F(SidebarBrowserTest, CreateSidebar) {
96 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
97 ClickBrowserAction(first_extension_id());
98 EXPECT_TRUE(IsShowingSidebar(first_extension_id()));
99 ClickBrowserAction(first_extension_id());
100 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
101 }
102
103 // Tests that sidebar visible at the other tabs
104 IN_PROC_BROWSER_TEST_F(SidebarBrowserTest, SwitchingTabs) {
105 // Open sidebar and move to a new tab
106 ClickBrowserAction(first_extension_id());
107 AddTabAtIndex(0, GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_TYPED);
108 EXPECT_TRUE(IsShowingSidebar(first_extension_id()));
109
110 // Close sidebar and switch back to the first tab
111 ClickBrowserAction(first_extension_id());
112 TabStripModel* tab_strip_model = browser()->tab_strip_model();
113 tab_strip_model->ActivateTabAt(0, false);
114 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
115 }
116
117 // Tests that sidebars are not shown if open_in_sidebar: false
118 IN_PROC_BROWSER_TEST_F(SidebarBrowserTest, CreateDisabledSidebar) {
119 DisableOpenInSidebar();
120 ClickBrowserAction(first_extension_id());
121 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
122 }
123
124 // Tests that cliking on the browser action show/hides the sidebar
125 IN_PROC_BROWSER_TEST_F(SidebarBrowserTest, MultipleExtensions) {
126 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
127 EXPECT_FALSE(IsShowingSidebar(second_extension_id()));
128 ClickBrowserAction(first_extension_id());
129 EXPECT_TRUE(IsShowingSidebar(first_extension_id()));
130 EXPECT_FALSE(IsShowingSidebar(second_extension_id()));
131
132 ClickBrowserAction(second_extension_id());
133 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
134 EXPECT_TRUE(IsShowingSidebar(second_extension_id()));
135
136 ClickBrowserAction(second_extension_id());
137 EXPECT_FALSE(IsShowingSidebar(first_extension_id()));
138 EXPECT_FALSE(IsShowingSidebar(second_extension_id()));
139 }
140
141 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698