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

Unified Diff: chrome/browser/extensions/extension_tabs_test.cc

Issue 8969011: Added populate parameter to chrome.windows.get, chrome.windows.getCurrent, (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.cc ('k') | chrome/common/extensions/api/windows.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_tabs_test.cc
===================================================================
--- chrome/browser/extensions/extension_tabs_test.cc (revision 114958)
+++ chrome/browser/extensions/extension_tabs_test.cc (working copy)
@@ -23,12 +23,12 @@
#include "ui/gfx/rect.h"
using namespace extension_function_test_utils;
+namespace keys = extension_tabs_module_constants;
namespace {
class ExtensionTabsTest : public InProcessBrowserTest {
};
-
}
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetWindow) {
@@ -40,7 +40,7 @@
new GetWindowFunction(),
base::StringPrintf("[%u]", window_id + 1),
browser()),
- extension_tabs_module_constants::kWindowNotFoundError));
+ keys::kWindowNotFoundError));
// Basic window details.
// Need GetRestoredBound instead of GetBounds.
@@ -60,6 +60,18 @@
EXPECT_EQ(bounds.width(), GetInteger(result.get(), "width"));
EXPECT_EQ(bounds.height(), GetInteger(result.get(), "height"));
+ // With "populate" enabled.
+ result.reset(ToDictionary(
+ RunFunctionAndReturnResult(
+ new GetWindowFunction(),
+ base::StringPrintf("[%u, {\"populate\": true}]", window_id),
+ browser())));
+
+ EXPECT_EQ(window_id, GetInteger(result.get(), "id"));
+ // "populate" was enabled so tabs should be populated.
+ ListValue* tabs = NULL;
+ EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
+
// TODO(aa): Can't assume window is focused. On mac, calling Activate() from a
// browser test doesn't seem to do anything, so can't test the opposite
// either.
@@ -101,7 +113,7 @@
new GetWindowFunction(),
base::StringPrintf("[%u]", incognito_window_id),
browser()),
- extension_tabs_module_constants::kWindowNotFoundError));
+ keys::kWindowNotFoundError));
// With "include_incognito".
result.reset(ToDictionary(
@@ -113,6 +125,122 @@
EXPECT_TRUE(GetBoolean(result.get(), "incognito"));
}
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetCurrentWindow) {
+ int window_id = ExtensionTabUtil::GetWindowId(browser());
+ Browser* new_browser = CreateBrowser(browser()->profile());
+ int new_id = ExtensionTabUtil::GetWindowId(new_browser);
+
+ // Get the current window using new_browser.
+ scoped_ptr<base::DictionaryValue> result(ToDictionary(
+ RunFunctionAndReturnResult(
+ new GetCurrentWindowFunction(),
+ "[]",
+ new_browser)));
+
+ // The id should match the window id of the browser instance that was passed
+ // to RunFunctionAndReturnResult.
+ EXPECT_EQ(new_id, GetInteger(result.get(), "id"));
+ ListValue* tabs = NULL;
+ EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
+
+ // Get the current window using the old window and make the tabs populated.
+ result.reset(ToDictionary(
+ RunFunctionAndReturnResult(
+ new GetCurrentWindowFunction(),
+ "[{\"populate\": true}]",
+ browser())));
+
+ // The id should match the window id of the browser instance that was passed
+ // to RunFunctionAndReturnResult.
+ EXPECT_EQ(window_id, GetInteger(result.get(), "id"));
+ // "populate" was enabled so tabs should be populated.
+ EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) {
+ // Create a new window which making it the "last focused" window.
+ // Note that "last focused" means the "top" most window.
+ Browser* new_browser = CreateBrowser(browser()->profile());
+ int focused_window_id = ExtensionTabUtil::GetWindowId(new_browser);
+
+ scoped_ptr<base::DictionaryValue> result(ToDictionary(
+ RunFunctionAndReturnResult(
+ new GetLastFocusedWindowFunction(),
+ "[]",
+ new_browser)));
+
+ // The id should always match the last focused window and does not depend
+ // on what was passed to RunFunctionAndReturnResult.
+ EXPECT_EQ(focused_window_id, GetInteger(result.get(), "id"));
+ ListValue* tabs = NULL;
+ EXPECT_FALSE(result.get()->GetList(keys::kTabsKey, &tabs));
+
+ result.reset(ToDictionary(
+ RunFunctionAndReturnResult(
+ new GetLastFocusedWindowFunction(),
+ "[{\"populate\": true}]",
+ browser())));
+
+ // The id should always match the last focused window and does not depend
+ // on what was passed to RunFunctionAndReturnResult.
+ EXPECT_EQ(focused_window_id, GetInteger(result.get(), "id"));
+ // "populate" was enabled so tabs should be populated.
+ EXPECT_TRUE(result.get()->GetList(keys::kTabsKey, &tabs));
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetAllWindows) {
+ const size_t NUM_WINDOWS = 5;
+ std::set<int> window_ids;
+ std::set<int> result_ids;
+ window_ids.insert(ExtensionTabUtil::GetWindowId(browser()));
+
+ for (size_t i = 0; i < NUM_WINDOWS - 1; ++i) {
+ Browser* new_browser = CreateBrowser(browser()->profile());
+ window_ids.insert(ExtensionTabUtil::GetWindowId(new_browser));
+ }
+
+ scoped_ptr<base::ListValue> result(ToList(
+ RunFunctionAndReturnResult(
+ new GetAllWindowsFunction(),
+ "[]",
+ browser())));
+
+ ListValue* windows = result.get();
+ EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
+ for (size_t i = 0; i < NUM_WINDOWS; ++i) {
+ DictionaryValue* result_window = NULL;
+ EXPECT_TRUE(windows->GetDictionary(i, &result_window));
+ result_ids.insert(GetInteger(result_window, "id"));
+
+ // "populate" was not passed in so tabs are not populated.
+ ListValue* tabs = NULL;
+ EXPECT_FALSE(result_window->GetList(keys::kTabsKey, &tabs));
+ }
+ // The returned ids should contain all the current browser instance ids.
+ EXPECT_EQ(window_ids, result_ids);
+
+ result_ids.clear();
+ result.reset(ToList(
+ RunFunctionAndReturnResult(
+ new GetAllWindowsFunction(),
+ "[{\"populate\": true}]",
+ browser())));
+
+ windows = result.get();
+ EXPECT_EQ(NUM_WINDOWS, windows->GetSize());
+ for (size_t i = 0; i < windows->GetSize(); ++i) {
+ DictionaryValue* result_window = NULL;
+ EXPECT_TRUE(windows->GetDictionary(i, &result_window));
+ result_ids.insert(GetInteger(result_window, "id"));
+
+ // "populate" was enabled so tabs should be populated.
+ ListValue* tabs = NULL;
+ EXPECT_TRUE(result_window->GetList(keys::kTabsKey, &tabs));
+ }
+ // The returned ids should contain all the current browser instance ids.
+ EXPECT_EQ(window_ids, result_ids);
+}
+
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, UpdateNoPermissions) {
// The test empty extension has no permissions, therefore it should not get
// tab data in the function result.
@@ -216,7 +344,7 @@
new CreateWindowFunction(),
kArgsWithExplicitIncognitoParam,
browser()),
- extension_tabs_module_constants::kIncognitoModeIsForced));
+ keys::kIncognitoModeIsForced));
// Now try opening a normal window from incognito window.
Browser* incognito_browser = CreateIncognitoBrowser();
@@ -226,7 +354,7 @@
new CreateWindowFunction(),
kArgsWithExplicitIncognitoParam,
incognito_browser),
- extension_tabs_module_constants::kIncognitoModeIsForced));
+ keys::kIncognitoModeIsForced));
}
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest,
@@ -244,7 +372,7 @@
new CreateWindowFunction(),
kArgs,
browser()),
- extension_tabs_module_constants::kIncognitoModeIsDisabled));
+ keys::kIncognitoModeIsDisabled));
// Run in incognito window.
EXPECT_TRUE(MatchPattern(
@@ -252,7 +380,7 @@
new CreateWindowFunction(),
kArgs,
incognito_browser),
- extension_tabs_module_constants::kIncognitoModeIsDisabled));
+ keys::kIncognitoModeIsDisabled));
}
#if defined(USE_AURA)
@@ -278,26 +406,26 @@
new UpdateWindowFunction(),
base::StringPrintf(kArgsMinimizedWithFocus, window_id),
browser()),
- extension_tabs_module_constants::kInvalidWindowStateError));
+ keys::kInvalidWindowStateError));
EXPECT_TRUE(MatchPattern(
RunFunctionAndReturnError(
new UpdateWindowFunction(),
base::StringPrintf(kArgsMaximizedWithoutFocus, window_id),
browser()),
- extension_tabs_module_constants::kInvalidWindowStateError));
+ keys::kInvalidWindowStateError));
EXPECT_TRUE(MatchPattern(
RunFunctionAndReturnError(
new UpdateWindowFunction(),
base::StringPrintf(kArgsMinimizedWithBounds, window_id),
browser()),
- extension_tabs_module_constants::kInvalidWindowStateError));
+ keys::kInvalidWindowStateError));
EXPECT_TRUE(MatchPattern(
RunFunctionAndReturnError(
new UpdateWindowFunction(),
base::StringPrintf(kArgsMaximizedWithBounds, window_id),
browser()),
- extension_tabs_module_constants::kInvalidWindowStateError));
+ keys::kInvalidWindowStateError));
}
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.cc ('k') | chrome/common/extensions/api/windows.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698