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

Side by Side Diff: chrome/browser/sidebar/sidebar_test.cc

Issue 6321006: Add "sidebar" section to extension manifest:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « chrome/browser/sidebar/sidebar_manager.cc ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/command_line.h"
6 #include "chrome/browser/browser_window.h"
7 #include "chrome/browser/sidebar/sidebar_manager.h"
8 #include "chrome/browser/tab_contents/tab_contents.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/in_process_browser_test.h"
13 #include "chrome/test/ui_test_utils.h"
14 #include "net/test/test_server.h"
15
16 namespace {
17
18 const char kSampleContentId[] = "sample_content_id";
19 const char kSimplePage[] = "files/sidebar/simple_page.html";
20
21 class SidebarTest : public InProcessBrowserTest {
22 public:
23 SidebarTest() {
24 CommandLine::ForCurrentProcess()->AppendSwitch(
25 switches::kEnableExperimentalExtensionApis);
26 set_show_window(true);
27 }
28
29 protected:
30 void ShowSidebarForCurrentTab() {
31 ShowSidebar(browser()->GetSelectedTabContents());
32 }
33
34 void ExpandSidebarForCurrentTab() {
35 ExpandSidebar(browser()->GetSelectedTabContents());
36 }
37
38 void CollapseSidebarForCurrentTab() {
39 CollapseSidebar(browser()->GetSelectedTabContents());
40 }
41
42 void HideSidebarForCurrentTab() {
43 HideSidebar(browser()->GetSelectedTabContents());
44 }
45
46 void NavigateSidebarForCurrentTabTo(const std::string& test_page) {
47 GURL url = test_server()->GetURL(test_page);
48
49 TabContents* tab = browser()->GetSelectedTabContents();
50
51 SidebarManager* sidebar_manager = SidebarManager::GetInstance();
52
53 sidebar_manager->NavigateSidebar(tab, kSampleContentId, url);
54
55 SidebarContainer* sidebar_container =
56 sidebar_manager->GetSidebarContainerFor(tab, kSampleContentId);
57
58 TabContents* client_contents = sidebar_container->sidebar_contents();
59 ui_test_utils::WaitForNavigation(&client_contents->controller());
60 }
61
62 void ShowSidebar(TabContents* tab) {
63 SidebarManager* sidebar_manager = SidebarManager::GetInstance();
64 sidebar_manager->ShowSidebar(tab, kSampleContentId);
65 }
66
67 void ExpandSidebar(TabContents* tab) {
68 SidebarManager* sidebar_manager = SidebarManager::GetInstance();
69 sidebar_manager->ExpandSidebar(tab, kSampleContentId);
70 if (browser()->GetSelectedTabContents() == tab)
71 EXPECT_GT(browser_view()->GetSidebarWidth(), 0);
72 }
73
74 void CollapseSidebar(TabContents* tab) {
75 SidebarManager* sidebar_manager = SidebarManager::GetInstance();
76 sidebar_manager->CollapseSidebar(tab, kSampleContentId);
77 if (browser()->GetSelectedTabContents() == tab)
78 EXPECT_EQ(0, browser_view()->GetSidebarWidth());
79 }
80
81 void HideSidebar(TabContents* tab) {
82 SidebarManager* sidebar_manager = SidebarManager::GetInstance();
83 sidebar_manager->HideSidebar(tab, kSampleContentId);
84 if (browser()->GetSelectedTabContents() == tab)
85 EXPECT_EQ(0, browser_view()->GetSidebarWidth());
86 }
87
88 TabContents* tab_contents(int i) {
89 return browser()->GetTabContentsAt(i);
90 }
91
92 BrowserView* browser_view() const {
93 return static_cast<BrowserView*>(browser()->window());
94 }
95 };
96
97 IN_PROC_BROWSER_TEST_F(SidebarTest, OpenClose) {
98 ShowSidebarForCurrentTab();
99
100 ExpandSidebarForCurrentTab();
101 CollapseSidebarForCurrentTab();
102
103 ExpandSidebarForCurrentTab();
104 CollapseSidebarForCurrentTab();
105
106 ExpandSidebarForCurrentTab();
107 CollapseSidebarForCurrentTab();
108
109 HideSidebarForCurrentTab();
110
111 ShowSidebarForCurrentTab();
112
113 ExpandSidebarForCurrentTab();
114 CollapseSidebarForCurrentTab();
115
116 HideSidebarForCurrentTab();
117 }
118
119 IN_PROC_BROWSER_TEST_F(SidebarTest, SwitchingTabs) {
120 ShowSidebarForCurrentTab();
121 ExpandSidebarForCurrentTab();
122
123 browser()->NewTab();
124
125 // Make sure sidebar is not visbile for the newly opened tab.
126 EXPECT_EQ(0, browser_view()->GetSidebarWidth());
127
128 // Switch back to the first tab.
129 browser()->SelectNumberedTab(0);
130
131 // Make sure it is visible now.
132 EXPECT_GT(browser_view()->GetSidebarWidth(), 0);
133
134 HideSidebarForCurrentTab();
135 }
136
137 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarOnInactiveTab) {
138 ShowSidebarForCurrentTab();
139 ExpandSidebarForCurrentTab();
140
141 browser()->NewTab();
142
143 // Hide sidebar on inactive (first) tab.
144 HideSidebar(tab_contents(0));
145
146 // Switch back to the first tab.
147 browser()->SelectNumberedTab(0);
148
149 // Make sure sidebar is not visbile anymore.
150 EXPECT_EQ(0, browser_view()->GetSidebarWidth());
151
152 // Show sidebar on inactive (second) tab.
153 ShowSidebar(tab_contents(1));
154 ExpandSidebar(tab_contents(1));
155 // Make sure sidebar is not visible yet.
156 EXPECT_EQ(0, browser_view()->GetSidebarWidth());
157
158 // Switch back to the second tab.
159 browser()->SelectNumberedTab(1);
160 // Make sure sidebar is visible now.
161 EXPECT_GT(browser_view()->GetSidebarWidth(), 0);
162
163 HideSidebarForCurrentTab();
164 }
165
166 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarNavigate) {
167 ASSERT_TRUE(test_server()->Start());
168
169 ShowSidebarForCurrentTab();
170
171 NavigateSidebarForCurrentTabTo(kSimplePage);
172
173 HideSidebarForCurrentTab();
174 }
175
176 } // namespace
177
OLDNEW
« no previous file with comments | « chrome/browser/sidebar/sidebar_manager.cc ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698