Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/files/file_path.h" | |
| 6 #include "base/path_service.h" | |
| 7 #include "chrome/browser/extensions/browser_action_test_util.h" | |
| 8 #include "chrome/browser/extensions/extension_action_manager.h" | |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 10 #include "chrome/browser/extensions/extension_service.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_commands.h" | |
| 14 #include "chrome/browser/ui/browser_window.h" | |
| 15 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 17 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | |
| 18 #include "chrome/common/chrome_paths.h" | |
| 19 #include "chrome/common/chrome_switches.h" | |
| 20 #include "chrome/test/base/in_process_browser_test.h" | |
| 21 #include "chrome/test/base/ui_test_utils.h" | |
| 22 #include "extensions/common/extension.h" | |
| 23 | |
| 24 using content::NavigationController; | |
| 25 using content::WebContents; | |
| 26 | |
| 27 namespace extensions { | |
| 28 | |
| 29 class SidebarTest : public ExtensionBrowserTest { | |
|
Devlin
2015/07/30 17:56:46
Why does this need to be a browser test?
ltilve
2015/08/07 16:15:02
We have been earlier following the suggestion of t
| |
| 30 public: | |
| 31 SidebarTest() {} | |
| 32 ~SidebarTest() override {} | |
| 33 | |
| 34 protected: | |
| 35 // InProcessBrowserTest | |
| 36 void SetUpOnMainThread() override { | |
| 37 ExtensionBrowserTest::SetUpOnMainThread(); | |
| 38 | |
| 39 // Load test sidebar extension. | |
| 40 base::FilePath extension_path; | |
| 41 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path)); | |
| 42 extension_path = extension_path.AppendASCII("sidebar"); | |
| 43 extension_ = LoadExtension(extension_path); | |
| 44 | |
| 45 ASSERT_TRUE(extension_); | |
| 46 | |
| 47 browser_action_test_util_.reset(new BrowserActionTestUtil(browser())); | |
| 48 } | |
| 49 | |
| 50 ExtensionAction* GetBrowserAction(const Extension& extension) { | |
| 51 return ExtensionActionManager::Get(browser()->profile()) | |
| 52 ->GetBrowserAction(extension); | |
| 53 } | |
| 54 | |
| 55 void ClickExtensionBrowserAction() { | |
| 56 browser_action_test_util_.get()->Press(0); | |
| 57 } | |
| 58 | |
| 59 void DisableOpenInSidebar() { | |
| 60 GetBrowserAction(*extension_)->set_open_in_sidebar(false); | |
| 61 } | |
| 62 | |
| 63 ExtensionActionViewController* getExtensionActionViewController() { | |
| 64 return static_cast<ExtensionActionViewController*>( | |
| 65 browser_action_test_util_.get() | |
| 66 ->GetToolbarActionsBar() | |
| 67 ->GetActions()[0]); | |
| 68 } | |
| 69 | |
| 70 bool HasSidebarForCurrentTab() { | |
| 71 return getExtensionActionViewController()->is_showing_sidebar(); | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 const Extension* extension_; | |
| 76 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; | |
| 77 }; | |
| 78 | |
| 79 // Tests that cliking on the browser action show/hides the sidebar | |
| 80 IN_PROC_BROWSER_TEST_F(SidebarTest, CreateSidebar) { | |
| 81 EXPECT_FALSE(HasSidebarForCurrentTab()); | |
| 82 ClickExtensionBrowserAction(); | |
| 83 EXPECT_TRUE(HasSidebarForCurrentTab()); | |
| 84 ClickExtensionBrowserAction(); | |
| 85 EXPECT_FALSE(HasSidebarForCurrentTab()); | |
| 86 } | |
| 87 | |
| 88 // Tests that sidebar visible at the other tabs | |
| 89 IN_PROC_BROWSER_TEST_F(SidebarTest, SwitchingTabs) { | |
| 90 // Open sidebar and move to a new tab | |
| 91 ClickExtensionBrowserAction(); | |
| 92 AddTabAtIndex(0, GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_TYPED); | |
| 93 EXPECT_TRUE(HasSidebarForCurrentTab()); | |
| 94 | |
| 95 // Close sidebar and switch back to the first tab | |
| 96 ClickExtensionBrowserAction(); | |
| 97 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 98 tab_strip_model->ActivateTabAt(0, false); | |
| 99 EXPECT_FALSE(HasSidebarForCurrentTab()); | |
| 100 } | |
| 101 | |
| 102 // Tests that sidebars are not shown if open_in_sidebar: false | |
| 103 IN_PROC_BROWSER_TEST_F(SidebarTest, CreateDisabledSidebar) { | |
|
Devlin
2015/07/30 17:56:46
What about testing multiple extensions with sideba
ltilve
2015/08/07 16:15:02
Done.
| |
| 104 DisableOpenInSidebar(); | |
| 105 ClickExtensionBrowserAction(); | |
| 106 EXPECT_FALSE(HasSidebarForCurrentTab()); | |
| 107 } | |
| 108 | |
| 109 } // namespace extensions | |
| OLD | NEW |