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

Unified Diff: chrome/browser/extensions/sidebar_manager_unittest.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/sidebar_manager_unittest.cc
diff --git a/chrome/browser/extensions/sidebar_manager_unittest.cc b/chrome/browser/extensions/sidebar_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e5ea047617a7f6fea290af684440906591a2f8b
--- /dev/null
+++ b/chrome/browser/extensions/sidebar_manager_unittest.cc
@@ -0,0 +1,151 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/path_service.h"
+#include "chrome/browser/extensions/browser_action_test_util.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/sidebar_manager.h"
+#include "chrome/browser/extensions/test_extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/base/browser_with_test_window_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/web_contents.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/file_util.h"
+
+using content::NavigationController;
+using content::WebContents;
+using extensions::SidebarManager;
+
+namespace extensions {
+
+const char kSimplePage[] = "/simple_page.html";
+
+class SidebarManagerTest : public BrowserWithTestWindowTest {
+ public:
+ SidebarManagerTest() {}
+ ~SidebarManagerTest() {}
+
+ protected:
+ void SetUp() override {
+ BrowserWithTestWindowTest::SetUp();
+
+ // Load test sidebar extension.
+ base::FilePath extension_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extension_path));
+
+ TestExtensionSystem* system = static_cast<TestExtensionSystem*>(
+ ExtensionSystem::Get(browser()->profile()));
+
+ ExtensionService* extension_service = system->CreateExtensionService(
+ base::CommandLine::ForCurrentProcess(), extension_path, false);
+
+ extension_path = extension_path.AppendASCII("sidebar");
+
+ std::string error;
+ extension_ = file_util::LoadExtension(extension_path, Manifest::UNPACKED,
+ Extension::NO_FLAGS, &error);
+
+ ASSERT_TRUE(extension_.get());
+
+ extension_service->AddExtension(extension_.get());
+
+ browser_action_test_util_.reset(new BrowserActionTestUtil(browser()));
+
+ chrome::NewTab(browser());
+ browser()->tab_strip_model()->ActivateTabAt(0, false);
+ }
+
+ void CreateSidebarForCurrentTab() {
+ CreateSidebar(browser()->tab_strip_model()->GetActiveWebContents());
+ }
+
+ void CreateSidebar(WebContents* temp) {
+ SidebarManager* sidebar_manager =
+ SidebarManager::GetFromContext(browser()->profile());
+ GURL url("chrome-extension://" + extension_.get()->id() + kSimplePage);
+ sidebar_manager->CreateSidebar(temp, url, browser());
+ }
+
+ void HideSidebar(WebContents* temp) {
+ SidebarManager* sidebar_manager =
+ SidebarManager::GetFromContext(browser()->profile());
+ sidebar_manager->HideSidebar(temp);
+ EXPECT_FALSE(sidebar_manager->GetSidebarContainerFor(temp) != nullptr);
+ }
+
+ WebContents* web_contents(int i) {
+ return browser()->tab_strip_model()->GetWebContentsAt(i);
+ }
+
+ bool HasSidebarForCurrentTab() {
+ SidebarManager* sidebar_manager =
+ SidebarManager::GetFromContext(browser()->profile());
+ return sidebar_manager->GetSidebarContainerFor(
+ browser()->tab_strip_model()->GetActiveWebContents()) != nullptr;
+ }
+
+ private:
+ scoped_refptr<Extension> extension_;
+ scoped_ptr<BrowserActionTestUtil> browser_action_test_util_;
+};
+
+// Tests that creating/hiding sidebar
+TEST_F(SidebarManagerTest, CreateSidebar) {
Devlin 2015/07/07 21:39:30 Won't this be implicitly tested by any other test?
ltilve 2015/07/09 22:15:51 Done.
+ CreateSidebarForCurrentTab();
+ EXPECT_TRUE(HasSidebarForCurrentTab());
+ HideSidebar(web_contents(0));
+ EXPECT_FALSE(HasSidebarForCurrentTab());
+}
+
+// Tests that sidebar is only visible at the proper tab
+TEST_F(SidebarManagerTest, SwitchingTabs) {
+ CreateSidebarForCurrentTab();
+ chrome::NewTab(browser());
Devlin 2015/07/07 21:39:30 prefer BrowserWithTestWindowTest::AddTab().
ltilve 2015/07/09 22:15:51 Done.
+
+ // Make sure sidebar is not visbile for the newly opened tab.
+ EXPECT_FALSE(HasSidebarForCurrentTab());
+
+ // Switch back to the first tab.
+ TabStripModel* tab_strip_model = browser()->tab_strip_model();
+ tab_strip_model->ActivateTabAt(0, false);
+
+ // Make sure it is visible now.
+ EXPECT_TRUE(HasSidebarForCurrentTab());
+
+ HideSidebar(web_contents(0));
+
+ // Make sure it is not visible any more
+ EXPECT_FALSE(HasSidebarForCurrentTab());
+}
+
+// Tests hiding sidebars on inactive tabs
+TEST_F(SidebarManagerTest, SidebarOnInactiveTab) {
Devlin 2015/07/07 21:39:30 All these tests can probably be combined into one.
ltilve 2015/07/09 22:15:51 Done.
+ CreateSidebarForCurrentTab();
+ chrome::NewTab(browser());
+
+ // Hide sidebar on inactive (first) tab.
+ HideSidebar(web_contents(0));
+
+ // Switch back to the first tab.
+ TabStripModel* tab_strip_model = browser()->tab_strip_model();
+ tab_strip_model->ActivateTabAt(0, false);
+
+ // Make sure sidebar is not visbile anymore.
+ EXPECT_FALSE(HasSidebarForCurrentTab());
+
+ // Show sidebar on inactive (second) tab.
+ CreateSidebar(web_contents(1));
+
+ // Make sure sidebar is not visible yet.
+ EXPECT_FALSE(HasSidebarForCurrentTab());
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698