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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 225093019: Zoom Extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using callbacks instead of zoom IDs. Created 6 years, 8 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/api/tabs/tabs_test.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_test.cc b/chrome/browser/extensions/api/tabs/tabs_test.cc
index 0ce9e1f569b34e96d9624dca7a59b9bb7a828344..87dd20f9af38312b13f609e6b27259506797f682 100644
--- a/chrome/browser/extensions/api/tabs/tabs_test.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_test.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/common/page_zoom.h"
#include "ui/gfx/rect.h"
namespace extensions {
@@ -590,4 +591,181 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTabNoPermission) {
EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
}
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, SetAndGetZoom) {
+ static const char kNewTestTabArgs[] = "about:blank";
+ content::OpenURLParams params(GURL(kNewTestTabArgs), content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK, false);
+ content::WebContents* web_contents = browser()->OpenURL(params);
+ int tab_id = ExtensionTabUtil::GetTabId(web_contents);
+
+ scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
+
+ // chrome.tabs.setZoom().
+ scoped_refptr<TabsSetZoomFunction> set_zoom_function(
+ new TabsSetZoomFunction());
+ set_zoom_function->set_extension(empty_extension.get());
+ set_zoom_function->set_has_callback(true);
+
+ // chrome.tabs.getZoom().
+ scoped_refptr<TabsGetZoomFunction> get_zoom_function(
+ new TabsGetZoomFunction());
+ get_zoom_function->set_extension(empty_extension.get());
+ get_zoom_function->set_has_callback(true);
+
+ // Test chrome.tabs.setZoom().
+ utils::RunFunction(set_zoom_function.get(),
+ base::StringPrintf("[%u, 0.8]", tab_id),
+ browser());
not at google - send to devlin 2014/04/09 03:52:11 it seems clearer to me to actually run the get/set
paulmeyer 2014/04/11 03:01:02 Done.
+ EXPECT_EQ(0.8, content::ZoomLevelToZoomFactor(web_contents->GetZoomLevel()));
+
+ // Test chrome.tabs.getZoom().
+ scoped_ptr<base::Value> get_zoom_result(
+ utils::RunFunctionAndReturnSingleResult(
+ get_zoom_function.get(), base::StringPrintf("[%u]", tab_id),
+ browser()));
+ double zoom_factor = -1;
+ get_zoom_result->GetAsDouble(&zoom_factor);
+ EXPECT_EQ(0.8, zoom_factor);
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, ZoomSettings) {
+ static const char kNewTestTabArgsA[] = "data:text/html,A";
+ static const char kNewTestTabArgsB[] = "data:text/html,B";
+
+ content::OpenURLParams params_A(GURL(kNewTestTabArgsA), content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK, false);
+ content::OpenURLParams params_B(GURL(kNewTestTabArgsB), content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK, false);
+
+ // Tabs A1 and A2 are navigated to the same origin, while B is navigated
+ // to a different one.
+ content::WebContents* web_contents_A1 = browser()->OpenURL(params_A);
+ content::WebContents* web_contents_A2 = browser()->OpenURL(params_A);
+ content::WebContents* web_contents_B = browser()->OpenURL(params_B);
+ int tab_id_A1 = ExtensionTabUtil::GetTabId(web_contents_A1);
+ int tab_id_A2 = ExtensionTabUtil::GetTabId(web_contents_A2);
+ int tab_id_B = ExtensionTabUtil::GetTabId(web_contents_B);
+
+ scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
+
+ // chrome.tabs.setZoom().
+ scoped_refptr<TabsSetZoomFunction> set_zoom_function(
+ new TabsSetZoomFunction());
not at google - send to devlin 2014/04/09 03:52:11 perhaps you should have a helper function which ge
paulmeyer 2014/04/11 03:01:02 Done. Wow, you were right, that does look much bet
+ set_zoom_function->set_extension(empty_extension.get());
+ set_zoom_function->set_has_callback(true);
+
+ // chrome.tabs.setZoomSettings().
+ scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function(
+ new TabsSetZoomSettingsFunction());
+ set_zoom_settings_function->set_extension(empty_extension.get());
+
+ // Test per-origin automatic zoom settings.
+ utils::RunFunction(set_zoom_function.get(),
+ base::StringPrintf("[%u, 1]", tab_id_B),
+ browser());
+ set_zoom_function = new TabsSetZoomFunction();
+ set_zoom_function->set_extension(empty_extension.get());
+ set_zoom_function->set_has_callback(true);
+ utils::RunFunction(set_zoom_function.get(),
+ base::StringPrintf("[%u, 1.1]", tab_id_A1),
+ browser());
+ EXPECT_EQ(1.1,
+ content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
+ EXPECT_EQ(1.1,
+ content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
+ EXPECT_EQ(1,
+ content::ZoomLevelToZoomFactor(web_contents_B->GetZoomLevel()));
+
+ // Test per-tab automatic zoom settings.
+ utils::RunFunction(set_zoom_settings_function.get(),
+ base::StringPrintf("[%u, {\"mode\": \"automatic\", "
+ "\"scope\": \"per-tab\"}]", tab_id_A1),
+ browser());
+ set_zoom_function = new TabsSetZoomFunction();
+ set_zoom_function->set_extension(empty_extension.get());
+ set_zoom_function->set_has_callback(true);
+ utils::RunFunction(set_zoom_function.get(),
+ base::StringPrintf("[%u, 1.2]", tab_id_A1),
+ browser());
+ EXPECT_EQ(1.2,
+ content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
+ EXPECT_EQ(1.1,
+ content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
+
+ // Test 'manual' mode.
+ set_zoom_settings_function = new TabsSetZoomSettingsFunction();
+ set_zoom_settings_function->set_extension(empty_extension.get());
+ utils::RunFunction(set_zoom_settings_function.get(),
+ base::StringPrintf("[%u, {\"mode\": \"manual\"}]",
+ tab_id_A1),
+ browser());
+ set_zoom_function = new TabsSetZoomFunction();
+ set_zoom_function->set_extension(empty_extension.get());
+ set_zoom_function->set_has_callback(true);
+ utils::RunFunction(set_zoom_function.get(),
+ base::StringPrintf("[%u, 1.3]", tab_id_A1),
+ browser());
+ EXPECT_EQ(1.3,
+ content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
+ EXPECT_EQ(1.1,
+ content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
+
+ // Test 'disabled' mode.
+ set_zoom_settings_function = new TabsSetZoomSettingsFunction();
+ set_zoom_settings_function->set_extension(empty_extension.get());
+ utils::RunFunction(set_zoom_settings_function.get(),
+ base::StringPrintf("[%u, {\"mode\": \"disabled\"}]",
+ tab_id_A1),
+ browser());
+ set_zoom_function = new TabsSetZoomFunction();
+ set_zoom_function->set_extension(empty_extension.get());
+ set_zoom_function->set_has_callback(true);
+ utils::RunFunction(set_zoom_function.get(),
+ base::StringPrintf("[%u, 1.4]", tab_id_A2),
+ browser());
+ EXPECT_EQ(1,
+ content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
+ EXPECT_EQ(1.4,
+ content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetZoomSettings) {
+ static const char kNewTestTabArgs[] = "about:blank";
+ content::OpenURLParams params(GURL(kNewTestTabArgs), content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK, false);
+ content::WebContents* web_contents = browser()->OpenURL(params);
+ int tab_id = ExtensionTabUtil::GetTabId(web_contents);
+
+ scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
+
+ // chrome.tabs.setZoomSettings().
+ scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function(
+ new TabsSetZoomSettingsFunction());
+ set_zoom_settings_function->set_extension(empty_extension.get());
+
+ // chrome.tabs.getZoomSettings().
+ scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function(
+ new TabsGetZoomSettingsFunction());
+ get_zoom_settings_function->set_extension(empty_extension.get());
+ get_zoom_settings_function->set_has_callback(true);
+
+ utils::RunFunction(set_zoom_settings_function.get(),
+ base::StringPrintf("[%u, {\"mode\": \"automatic\", "
+ "\"scope\": \"per-tab\"}]", tab_id),
+ browser());
+ scoped_ptr<base::DictionaryValue> get_zoom_settings_result(
+ utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
+ get_zoom_settings_function.get(), base::StringPrintf("[%u]", tab_id),
+ browser())));
+
+ std::string mode = utils::GetString(get_zoom_settings_result.get(), "mode");
+ std::string scope = utils::GetString(get_zoom_settings_result.get(), "scope");
+ EXPECT_EQ("automatic", mode);
+ EXPECT_EQ("per-tab", scope);
+}
not at google - send to devlin 2014/04/09 03:52:11 also test the chrome:// URL stuff.
paulmeyer 2014/04/11 03:01:02 Done.
+
not at google - send to devlin 2014/04/09 03:52:11 otherwise: great tests!
paulmeyer 2014/04/11 03:01:02 Thanks! On 2014/04/09 03:52:11, kalman wrote:
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698