summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 18:05:56 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 18:05:56 +0000
commit8b8e7c9bce4198a4ee2865d9dfce6e8baa173ad3 (patch)
tree938304b8e1be417c1b9c73d7463dacbc1da79843 /chrome/test
parentf2c4ee3627e6039fd42bd7c0c93e902b72653449 (diff)
downloadchromium_src-8b8e7c9bce4198a4ee2865d9dfce6e8baa173ad3.zip
chromium_src-8b8e7c9bce4198a4ee2865d9dfce6e8baa173ad3.tar.gz
chromium_src-8b8e7c9bce4198a4ee2865d9dfce6e8baa173ad3.tar.bz2
Initial version of chrome.experimental.sidebar extension API.
BUG=51084 TEST=Run interactive_ui_tests and browser_tests. New: - sidebar Extension API (design doc: https://docs.google.com/a/google.com/Doc?docid=0AV4Qg3xyZ8RQZGZtbWIydDJfNWc0eHJtbmRm&hl=en); - Sidebar panel in Chrome browser view; Original review=http://codereview.chromium.org/2836040/show Patch by alekseys@google.com git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/api_test/sidebar/manifest.json7
-rw-r--r--chrome/test/data/extensions/api_test/sidebar/simple_page.html6
-rw-r--r--chrome/test/data/extensions/api_test/sidebar/test.html1
-rw-r--r--chrome/test/data/extensions/api_test/sidebar/test.js226
-rw-r--r--chrome/test/interactive_ui/interactive_ui_tests.gypi2
-rw-r--r--chrome/test/testing_browser_process.h4
6 files changed, 246 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/api_test/sidebar/manifest.json b/chrome/test/data/extensions/api_test/sidebar/manifest.json
new file mode 100644
index 0000000..4a55643
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/sidebar/manifest.json
@@ -0,0 +1,7 @@
+{
+ "name": "chrome.experimental.sidebar",
+ "version": "0.1",
+ "description": "end-to-end browser test for chrome.experimental.sidebar API",
+ "background_page": "test.html",
+ "permissions": ["tabs", "experimental"]
+}
diff --git a/chrome/test/data/extensions/api_test/sidebar/simple_page.html b/chrome/test/data/extensions/api_test/sidebar/simple_page.html
new file mode 100644
index 0000000..f8b6c17
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/sidebar/simple_page.html
@@ -0,0 +1,6 @@
+<html>
+ <head>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/chrome/test/data/extensions/api_test/sidebar/test.html b/chrome/test/data/extensions/api_test/sidebar/test.html
new file mode 100644
index 0000000..46f4d74
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/sidebar/test.html
@@ -0,0 +1 @@
+<script src="test.js"></script>
diff --git a/chrome/test/data/extensions/api_test/sidebar/test.js b/chrome/test/data/extensions/api_test/sidebar/test.js
new file mode 100644
index 0000000..56f810b
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/sidebar/test.js
@@ -0,0 +1,226 @@
+// Copyright (c) 2010 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.
+
+// API test for chrome.experimental.sidebar.
+// browser_tests.exe --gtest_filter=SidebarApiTest.Sidebar
+
+const assertEq = chrome.test.assertEq;
+const assertTrue = chrome.test.assertTrue;
+const pass = chrome.test.callbackPass;
+
+if (!chrome.sidebar) {
+ chrome.sidebar = chrome.experimental.sidebar;
+}
+
+/**
+* A helper function to show sidebar. Verifies that sidebar was hidden before
+* and is shown after the call.
+* @param {id} tab id to expand sidebar for.
+* @param {function} callback Closure.
+*/
+function showSidebar(id, callback) {
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ assertEq('hidden', state);
+ chrome.sidebar.show({tabId: id});
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ assertEq('shown', state);
+ callback();
+ });
+ });
+}
+
+/**
+* A helper function to expand sidebar. Verifies that sidebar was shown
+* before and is expanded after the call (provided the specified tab
+* is currently selected).
+* @param {id} tab id to expand sidebar for.
+* @param {function} callback Closure.
+*/
+function expandSidebar(id, callback) {
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ assertEq('shown', state);
+ chrome.sidebar.expand({tabId: id});
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ if (undefined == id) {
+ assertEq('active', state);
+ callback();
+ } else {
+ chrome.tabs.get(id, function(tab) {
+ if (tab.selected) {
+ assertEq('active', state);
+ } else {
+ assertEq('shown', state);
+ }
+ callback();
+ });
+ }
+ });
+ });
+}
+
+/**
+* A helper function to collapse sidebar. Verifies that sidebar was active
+* before (provided the specified tab is currently selected) and is not active
+* after the call.
+* @param {id} tab id to collapse sidebar for.
+* @param {function} callback Closure.
+*/
+function collapseSidebar(id, callback) {
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ if (undefined == id) {
+ assertEq('active', state);
+ } else {
+ chrome.tabs.get(id, function(tab) {
+ if (tab.selected) {
+ assertEq('active', state);
+ } else {
+ assertEq('shown', state);
+ }
+ });
+ }
+ chrome.sidebar.collapse({tabId: id});
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ assertEq('shown', state);
+ callback();
+ });
+ });
+}
+
+/**
+* A helper function to hide sidebar. Verifies that sidebar was not hidden
+* before and is hidden after the call.
+* @param {id} tab id to hide sidebar for.
+* @param {function} callback Closure.
+*/
+function hideSidebar(id, callback) {
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ assertTrue('hidden' != state);
+ chrome.sidebar.hide({tabId: id});
+ chrome.sidebar.getState({tabId: id}, function(state) {
+ assertEq('hidden', state);
+ callback();
+ });
+ });
+}
+
+/**
+* A helper function to show sidebar for the current tab.
+* @param {function} callback Closure.
+*/
+function showSidebarForCurrentTab(callback) {
+ showSidebar(undefined, callback);
+}
+
+/**
+* A helper function to expand sidebar for the current tab.
+* @param {function} callback Closure.
+*/
+function expandSidebarForCurrentTab(callback) {
+ expandSidebar(undefined, callback);
+}
+
+/**
+* A helper function to collapse sidebar for the current tab.
+* @param {function} callback Closure.
+*/
+function collapseSidebarForCurrentTab(callback) {
+ collapseSidebar(undefined, callback);
+}
+
+/**
+* A helper function to hide sidebar for the current tab.
+* @param {function} callback Closure.
+*/
+function hideSidebarForCurrentTab(callback) {
+ hideSidebar(undefined, callback);
+}
+
+var tests = [
+ function showHideSidebar() {
+ showSidebarForCurrentTab(function() {
+ expandSidebarForCurrentTab(function() {
+ collapseSidebarForCurrentTab(function() {
+ hideSidebarForCurrentTab(function() {
+ showSidebarForCurrentTab(function() {
+ hideSidebarForCurrentTab(pass());
+ });
+ });
+ });
+ });
+ });
+ },
+
+ function switchingTabs() {
+ showSidebarForCurrentTab(function() {
+ expandSidebarForCurrentTab(function() {
+ chrome.tabs.getSelected(null, function(tabWithSidebar) {
+ chrome.tabs.create({}, function(tab) {
+ // Make sure sidebar is not visible on this new tab.
+ chrome.sidebar.getState({}, function(state) {
+ assertEq('hidden', state);
+ // Switch back to the tab with the sidebar.
+ chrome.tabs.update(tabWithSidebar.id, {selected: true},
+ function(theSameTab) {
+ // It makes sure sidebar is visible before hiding it.
+ hideSidebarForCurrentTab(pass());
+ });
+ });
+ });
+ });
+ });
+ });
+ },
+
+ function sidebarOnInactiveTab() {
+ // 'switchingTabs' test created two tabs.
+ chrome.tabs.getAllInWindow(null, function(tabs) {
+ assertEq(2, tabs.length);
+ showSidebar(tabs[1].id, function() {
+ expandSidebar(tabs[1].id, function() {
+ // Make sure sidebar is not visible on the current tab.
+ chrome.sidebar.getState({}, function(state) {
+ assertEq('hidden', state);
+ // Switch to the tab with the sidebar.
+ chrome.tabs.update(tabs[1].id, {selected: true},
+ function() {
+ // Make sure sidebar is visible on the current tab.
+ chrome.sidebar.getState({}, function(state) {
+ assertEq('active', state);
+
+ // Switch to the tab with no sidebar.
+ chrome.tabs.update(tabs[0].id, {selected: true},
+ function() {
+ collapseSidebar(tabs[1].id, function() {
+ hideSidebar(tabs[1].id, pass());
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+ },
+
+ function navigateSidebar() {
+ showSidebarForCurrentTab(function() {
+ expandSidebarForCurrentTab(function() {
+ chrome.sidebar.navigate({url: 'simple_page.html'});
+ hideSidebarForCurrentTab(pass());
+ });
+ });
+ },
+
+ function testSetFunctions() {
+ showSidebarForCurrentTab(function() {
+ // TODO(alekseys): test unicode strings.
+ chrome.sidebar.setBadgeText({text: 'Some random text'});
+ chrome.sidebar.setIcon({path: 'icon.png'});
+ chrome.sidebar.setTitle({title: 'Some random title'});
+ hideSidebarForCurrentTab(pass());
+ });
+ }
+];
+
+chrome.test.runTests(tests);
diff --git a/chrome/test/interactive_ui/interactive_ui_tests.gypi b/chrome/test/interactive_ui/interactive_ui_tests.gypi
index 72c60c7..856e043 100644
--- a/chrome/test/interactive_ui/interactive_ui_tests.gypi
+++ b/chrome/test/interactive_ui/interactive_ui_tests.gypi
@@ -145,6 +145,8 @@
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.rc',
'<(DEPTH)/chrome/browser/accessibility_win_browsertest.cc',
+ # TODO: port sidebar.
+ '<(DEPTH)/chrome/browser/sidebar/sidebar_test.cc',
'<(DEPTH)/chrome/browser/views/browser_views_accessibility_browsertest.cc',
],
'conditions': [
diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h
index 65f6cca..73c10db 100644
--- a/chrome/test/testing_browser_process.h
+++ b/chrome/test/testing_browser_process.h
@@ -87,6 +87,10 @@ class TestingBrowserProcess : public BrowserProcess {
return NULL;
}
+ virtual SidebarManager* sidebar_manager() {
+ return NULL;
+ }
+
virtual TabCloseableStateWatcher* tab_closeable_state_watcher() {
return NULL;
}