| OLD | NEW |
| (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 "base/file_path.h" | |
| 7 #include "base/memory/ref_counted.h" | |
| 8 #include "base/path_service.h" | |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 10 #include "chrome/browser/sidebar/sidebar_manager.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_window.h" | |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 14 #include "chrome/common/chrome_paths.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "chrome/common/extensions/extension.h" | |
| 17 #include "chrome/test/base/in_process_browser_test.h" | |
| 18 #include "chrome/test/base/ui_test_utils.h" | |
| 19 #include "content/browser/tab_contents/tab_contents.h" | |
| 20 #include "net/test/test_server.h" | |
| 21 | |
| 22 #include "chrome/browser/extensions/extension_service.h" | |
| 23 #include "chrome/browser/profiles/profile.h" | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 const char kSimplePage[] = "files/sidebar/simple_page.html"; | |
| 28 | |
| 29 class SidebarTest : public ExtensionBrowserTest { | |
| 30 public: | |
| 31 SidebarTest() { | |
| 32 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 33 switches::kEnableExperimentalExtensionApis); | |
| 34 } | |
| 35 | |
| 36 protected: | |
| 37 // InProcessBrowserTest overrides. | |
| 38 virtual void SetUpOnMainThread() { | |
| 39 ExtensionBrowserTest::SetUpOnMainThread(); | |
| 40 | |
| 41 // Load test sidebar extension. | |
| 42 FilePath extension_path; | |
| 43 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path)); | |
| 44 extension_path = extension_path.AppendASCII("sidebar"); | |
| 45 | |
| 46 ASSERT_TRUE(LoadExtension(extension_path)); | |
| 47 | |
| 48 // For now content_id == extension_id. | |
| 49 content_id_ = last_loaded_extension_id_; | |
| 50 } | |
| 51 | |
| 52 void ShowSidebarForCurrentTab() { | |
| 53 ShowSidebar(browser()->GetSelectedTabContents()); | |
| 54 } | |
| 55 | |
| 56 void ExpandSidebarForCurrentTab() { | |
| 57 ExpandSidebar(browser()->GetSelectedTabContents()); | |
| 58 } | |
| 59 | |
| 60 void CollapseSidebarForCurrentTab() { | |
| 61 CollapseSidebar(browser()->GetSelectedTabContents()); | |
| 62 } | |
| 63 | |
| 64 void HideSidebarForCurrentTab() { | |
| 65 HideSidebar(browser()->GetSelectedTabContents()); | |
| 66 } | |
| 67 | |
| 68 void NavigateSidebarForCurrentTabTo(const std::string& test_page) { | |
| 69 GURL url = test_server()->GetURL(test_page); | |
| 70 | |
| 71 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 72 | |
| 73 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | |
| 74 SidebarContainer* sidebar_container = | |
| 75 sidebar_manager->GetSidebarContainerFor(tab, content_id_); | |
| 76 TabContents* client_contents = sidebar_container->sidebar_contents(); | |
| 77 | |
| 78 ui_test_utils::WindowedNotificationObserver observer( | |
| 79 content::NOTIFICATION_LOAD_STOP, | |
| 80 content::Source<NavigationController>(&client_contents->controller())); | |
| 81 sidebar_manager->NavigateSidebar(tab, content_id_, url); | |
| 82 observer.Wait(); | |
| 83 } | |
| 84 | |
| 85 void ShowSidebar(TabContents* tab) { | |
| 86 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | |
| 87 sidebar_manager->ShowSidebar(tab, content_id_); | |
| 88 } | |
| 89 | |
| 90 void ExpandSidebar(TabContents* tab) { | |
| 91 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | |
| 92 sidebar_manager->ExpandSidebar(tab, content_id_); | |
| 93 if (browser()->GetSelectedTabContents() == tab) | |
| 94 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); | |
| 95 } | |
| 96 | |
| 97 void CollapseSidebar(TabContents* tab) { | |
| 98 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | |
| 99 sidebar_manager->CollapseSidebar(tab, content_id_); | |
| 100 if (browser()->GetSelectedTabContents() == tab) | |
| 101 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | |
| 102 } | |
| 103 | |
| 104 void HideSidebar(TabContents* tab) { | |
| 105 SidebarManager* sidebar_manager = SidebarManager::GetInstance(); | |
| 106 sidebar_manager->HideSidebar(tab, content_id_); | |
| 107 if (browser()->GetSelectedTabContents() == tab) | |
| 108 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | |
| 109 } | |
| 110 | |
| 111 TabContents* tab_contents(int i) { | |
| 112 return browser()->GetTabContentsAt(i); | |
| 113 } | |
| 114 | |
| 115 BrowserView* browser_view() const { | |
| 116 return static_cast<BrowserView*>(browser()->window()); | |
| 117 } | |
| 118 | |
| 119 private: | |
| 120 std::string content_id_; | |
| 121 }; | |
| 122 | |
| 123 IN_PROC_BROWSER_TEST_F(SidebarTest, OpenClose) { | |
| 124 ShowSidebarForCurrentTab(); | |
| 125 | |
| 126 ExpandSidebarForCurrentTab(); | |
| 127 CollapseSidebarForCurrentTab(); | |
| 128 | |
| 129 ExpandSidebarForCurrentTab(); | |
| 130 CollapseSidebarForCurrentTab(); | |
| 131 | |
| 132 ExpandSidebarForCurrentTab(); | |
| 133 CollapseSidebarForCurrentTab(); | |
| 134 | |
| 135 HideSidebarForCurrentTab(); | |
| 136 | |
| 137 ShowSidebarForCurrentTab(); | |
| 138 | |
| 139 ExpandSidebarForCurrentTab(); | |
| 140 CollapseSidebarForCurrentTab(); | |
| 141 | |
| 142 HideSidebarForCurrentTab(); | |
| 143 } | |
| 144 | |
| 145 IN_PROC_BROWSER_TEST_F(SidebarTest, SwitchingTabs) { | |
| 146 ShowSidebarForCurrentTab(); | |
| 147 ExpandSidebarForCurrentTab(); | |
| 148 | |
| 149 browser()->NewTab(); | |
| 150 | |
| 151 // Make sure sidebar is not visbile for the newly opened tab. | |
| 152 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | |
| 153 | |
| 154 // Switch back to the first tab. | |
| 155 browser()->SelectNumberedTab(0); | |
| 156 | |
| 157 // Make sure it is visible now. | |
| 158 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); | |
| 159 | |
| 160 HideSidebarForCurrentTab(); | |
| 161 } | |
| 162 | |
| 163 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarOnInactiveTab) { | |
| 164 ShowSidebarForCurrentTab(); | |
| 165 ExpandSidebarForCurrentTab(); | |
| 166 | |
| 167 browser()->NewTab(); | |
| 168 | |
| 169 // Hide sidebar on inactive (first) tab. | |
| 170 HideSidebar(tab_contents(0)); | |
| 171 | |
| 172 // Switch back to the first tab. | |
| 173 browser()->SelectNumberedTab(0); | |
| 174 | |
| 175 // Make sure sidebar is not visbile anymore. | |
| 176 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | |
| 177 | |
| 178 // Show sidebar on inactive (second) tab. | |
| 179 ShowSidebar(tab_contents(1)); | |
| 180 ExpandSidebar(tab_contents(1)); | |
| 181 // Make sure sidebar is not visible yet. | |
| 182 EXPECT_EQ(0, browser_view()->GetSidebarWidth()); | |
| 183 | |
| 184 // Switch back to the second tab. | |
| 185 browser()->SelectNumberedTab(1); | |
| 186 // Make sure sidebar is visible now. | |
| 187 EXPECT_GT(browser_view()->GetSidebarWidth(), 0); | |
| 188 | |
| 189 HideSidebarForCurrentTab(); | |
| 190 } | |
| 191 | |
| 192 IN_PROC_BROWSER_TEST_F(SidebarTest, SidebarNavigate) { | |
| 193 ASSERT_TRUE(test_server()->Start()); | |
| 194 | |
| 195 ShowSidebarForCurrentTab(); | |
| 196 | |
| 197 NavigateSidebarForCurrentTabTo(kSimplePage); | |
| 198 | |
| 199 HideSidebarForCurrentTab(); | |
| 200 } | |
| 201 | |
| 202 } // namespace | |
| OLD | NEW |