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

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: Created 5 years, 6 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 (c) 2015 The Chromium Authors. All rights reserved.
Devlin 2015/06/19 19:56:09 no (c) (Goes for all new files)
ltilve 2015/06/28 22:44:19 Done for all the new files.
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 "base/command_line.h"
6 #include "base/files/file_path.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/path_service.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_action_manager.h"
11 #include "chrome/browser/extensions/extension_browsertest.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/sidebar_manager.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/web_contents.h"
24 #include "extensions/common/extension.h"
25
26 using content::NavigationController;
27 using content::WebContents;
28 using extensions::SidebarManager;
29
30 namespace extensions {
31
32 const char kSimplePage[] = "/simple_page.html";
33
34 class SidebarTest : public ExtensionBrowserTest {
Devlin 2015/06/19 19:56:09 This looks like it can be split into two tests: -
ltilve 2015/06/28 22:44:19 Done. We are now having SidebarManager unnittests
Devlin 2015/07/07 21:39:29 Is there a reason the browser tests can't be in th
ltilve 2015/07/09 22:15:50 I have moved them to the next patch set because as
Devlin 2015/07/10 20:18:41 I don't see why it should. HasSidebarForCurrentTa
ltilve 2015/07/17 16:26:22 Done. We have created two separated tests for the
35 public:
36 SidebarTest() {}
Devlin 2015/06/19 19:56:08 Please add a destructor
ltilve 2015/06/28 22:44:19 Done.
37
38 protected:
39 // InProcessBrowserTest overrides.
Devlin 2015/06/19 19:56:09 s/ overrides./: s/InProcessBrowserTest/ExtensionBr
ltilve 2015/06/28 22:44:19 Done.
40 void SetUpOnMainThread() override {
41 ExtensionBrowserTest::SetUpOnMainThread();
42
43 // Load test sidebar extension.
44 base::FilePath extension_path;
45 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path));
46 extension_path = extension_path.AppendASCII("sidebar");
47 extension_ = LoadExtension(extension_path);
48
49 ASSERT_TRUE(extension_);
50
51 content_id_ = last_loaded_extension_id();
52 }
53
54 ExtensionAction* GetBrowserAction(const Extension& extension) {
55 return ExtensionActionManager::Get(browser()->profile())
56 ->GetBrowserAction(extension);
57 }
58
59 BrowserActionTestUtil* GetBrowserActionsBar() {
60 if (!browser_action_test_util_)
61 browser_action_test_util_.reset(new BrowserActionTestUtil(browser()));
Devlin 2015/06/19 19:56:09 again, no real point in lazily initializing this.
ltilve 2015/06/28 22:44:19 Done.
62 return browser_action_test_util_.get();
63 }
64
65 void ClickExtensionBrowserAction() {
66 GetBrowserActionsBar()->Press(0);
67 }
68
69 void CreateSidebar(WebContents* temp) {
70 WebContents* tab = static_cast<WebContents*>(temp);
Devlin 2015/06/19 19:56:09 what does this line do (and the similar ones below
ltilve 2015/06/28 22:44:19 Done. Removed all of them.
71 SidebarManager* sidebar_manager =
72 SidebarManager::GetFromContext(browser()->profile());
73 GURL url("chrome-extension://" + content_id_ + kSimplePage);
74 sidebar_manager->CreateSidebar(tab, url, browser());
75 }
76
77 void HideSidebar(WebContents* temp) {
78 WebContents* tab = static_cast<WebContents*>(temp);
79 SidebarManager* sidebar_manager =
80 SidebarManager::GetFromContext(browser()->profile());
81 sidebar_manager->HideSidebar(tab);
82 EXPECT_FALSE(sidebar_manager->HasSidebar(tab));
83 }
84
85 WebContents* web_contents(int i) {
86 return static_cast<WebContents*>(
87 browser()->tab_strip_model()->GetWebContentsAt(i));
88 }
89
90 void DisableOpenInSidebar() {
91 GetBrowserAction(*extension_)->set_open_in_sidebar(false);
92 }
93
94 bool HasSidebarForCurrentTab() {
95 SidebarManager* sidebar_manager =
96 SidebarManager::GetFromContext(browser()->profile());
97 return sidebar_manager->HasSidebar(
98 browser()->tab_strip_model()->GetActiveWebContents());
99 }
100
101 private:
102 std::string content_id_;
103 const Extension* extension_;
104 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
Devlin 2015/06/19 19:56:09 DISALLOW_COPY_AND_ASSIGN
ltilve 2015/06/28 22:44:19 Done.
105 };
106
107 // Tests that cliking on the browser action show/hides the sidebar
108 IN_PROC_BROWSER_TEST_F(SidebarTest, CreateSidebar) {
109 ClickExtensionBrowserAction();
110 EXPECT_TRUE(HasSidebarForCurrentTab());
111 ClickExtensionBrowserAction();
112 EXPECT_FALSE(HasSidebarForCurrentTab());
113 }
114
115 // Tests that sidebars are not shown if open_in_sidebar: false
116 IN_PROC_BROWSER_TEST_F(SidebarTest, CreateDisabledSidebar) {
117 DisableOpenInSidebar();
118 ClickExtensionBrowserAction();
119 EXPECT_FALSE(HasSidebarForCurrentTab());
120 }
121
122 // Tests that sidebar is only visible at the proper tab
123 IN_PROC_BROWSER_TEST_F(SidebarTest, SwitchingTabs) {
124 ClickExtensionBrowserAction();
125 chrome::NewTab(browser());
126
127 // Make sure sidebar is not visbile for the newly opened tab.
128 EXPECT_FALSE(HasSidebarForCurrentTab());
129
130 // Switch back to the first tab.
131 TabStripModel* tab_strip_model = browser()->tab_strip_model();
132 tab_strip_model->ActivateTabAt(0, false);
133
134 // Make sure it is visible now.
135 EXPECT_TRUE(HasSidebarForCurrentTab());
136
137 ClickExtensionBrowserAction();
138
139 // Make sure it is not visible any more
140 EXPECT_FALSE(HasSidebarForCurrentTab());
141 }
142
143 // Tests hiding sidebars on inactive tabs
144 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarOnInactiveTab) {
145 ClickExtensionBrowserAction();
146 chrome::NewTab(browser());
147
148 // Hide sidebar on inactive (first) tab.
149 HideSidebar(web_contents(0));
150
151 // Switch back to the first tab.
152 TabStripModel* tab_strip_model = browser()->tab_strip_model();
153 tab_strip_model->ActivateTabAt(0, false);
154
155 // Make sure sidebar is not visbile anymore.
156 EXPECT_FALSE(HasSidebarForCurrentTab());
157
158 // Show sidebar on inactive (second) tab.
159 CreateSidebar(web_contents(1));
160
161 // Make sure sidebar is not visible yet.
162 EXPECT_FALSE(HasSidebarForCurrentTab());
163 }
164
165 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698