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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 14 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
16 #include "chrome/browser/extensions/extension_function_test_utils.h" 16 #include "chrome/browser/extensions/extension_function_test_utils.h"
17 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
18 #include "chrome/browser/prefs/incognito_mode_prefs.h" 18 #include "chrome/browser/prefs/incognito_mode_prefs.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h" 21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/common/page_zoom.h"
25 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
26 27
27 namespace extensions { 28 namespace extensions {
28 29
29 namespace keys = tabs_constants; 30 namespace keys = tabs_constants;
30 namespace utils = extension_function_test_utils; 31 namespace utils = extension_function_test_utils;
31 32
32 namespace { 33 namespace {
33 34
34 class ExtensionTabsTest : public InProcessBrowserTest { 35 class ExtensionTabsTest : public InProcessBrowserTest {
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); 584 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType());
584 // Duplicate tab id should be different from the original tab id. 585 // Duplicate tab id should be different from the original tab id.
585 EXPECT_NE(tab_id, duplicate_tab_id); 586 EXPECT_NE(tab_id, duplicate_tab_id);
586 EXPECT_EQ(window_id, duplicate_tab_window_id); 587 EXPECT_EQ(window_id, duplicate_tab_window_id);
587 EXPECT_EQ(tab_index + 1, duplicate_tab_index); 588 EXPECT_EQ(tab_index + 1, duplicate_tab_index);
588 // The test empty extension has no permissions, therefore |duplicate_result| 589 // The test empty extension has no permissions, therefore |duplicate_result|
589 // should not contain url, title, and faviconUrl in the function result. 590 // should not contain url, title, and faviconUrl in the function result.
590 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get())); 591 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
591 } 592 }
592 593
594 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, SetAndGetZoom) {
595 static const char kNewTestTabArgs[] = "about:blank";
596 content::OpenURLParams params(GURL(kNewTestTabArgs), content::Referrer(),
597 NEW_FOREGROUND_TAB,
598 content::PAGE_TRANSITION_LINK, false);
599 content::WebContents* web_contents = browser()->OpenURL(params);
600 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
601
602 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
603
604 // chrome.tabs.setZoom().
605 scoped_refptr<TabsSetZoomFunction> set_zoom_function(
606 new TabsSetZoomFunction());
607 set_zoom_function->set_extension(empty_extension.get());
608 set_zoom_function->set_has_callback(true);
609
610 // chrome.tabs.getZoom().
611 scoped_refptr<TabsGetZoomFunction> get_zoom_function(
612 new TabsGetZoomFunction());
613 get_zoom_function->set_extension(empty_extension.get());
614 get_zoom_function->set_has_callback(true);
615
616 // Test chrome.tabs.setZoom().
617 utils::RunFunction(set_zoom_function.get(),
618 base::StringPrintf("[%u, 0.8]", tab_id),
619 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.
620 EXPECT_EQ(0.8, content::ZoomLevelToZoomFactor(web_contents->GetZoomLevel()));
621
622 // Test chrome.tabs.getZoom().
623 scoped_ptr<base::Value> get_zoom_result(
624 utils::RunFunctionAndReturnSingleResult(
625 get_zoom_function.get(), base::StringPrintf("[%u]", tab_id),
626 browser()));
627 double zoom_factor = -1;
628 get_zoom_result->GetAsDouble(&zoom_factor);
629 EXPECT_EQ(0.8, zoom_factor);
630 }
631
632 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, ZoomSettings) {
633 static const char kNewTestTabArgsA[] = "data:text/html,A";
634 static const char kNewTestTabArgsB[] = "data:text/html,B";
635
636 content::OpenURLParams params_A(GURL(kNewTestTabArgsA), content::Referrer(),
637 NEW_FOREGROUND_TAB,
638 content::PAGE_TRANSITION_LINK, false);
639 content::OpenURLParams params_B(GURL(kNewTestTabArgsB), content::Referrer(),
640 NEW_FOREGROUND_TAB,
641 content::PAGE_TRANSITION_LINK, false);
642
643 // Tabs A1 and A2 are navigated to the same origin, while B is navigated
644 // to a different one.
645 content::WebContents* web_contents_A1 = browser()->OpenURL(params_A);
646 content::WebContents* web_contents_A2 = browser()->OpenURL(params_A);
647 content::WebContents* web_contents_B = browser()->OpenURL(params_B);
648 int tab_id_A1 = ExtensionTabUtil::GetTabId(web_contents_A1);
649 int tab_id_A2 = ExtensionTabUtil::GetTabId(web_contents_A2);
650 int tab_id_B = ExtensionTabUtil::GetTabId(web_contents_B);
651
652 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
653
654 // chrome.tabs.setZoom().
655 scoped_refptr<TabsSetZoomFunction> set_zoom_function(
656 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
657 set_zoom_function->set_extension(empty_extension.get());
658 set_zoom_function->set_has_callback(true);
659
660 // chrome.tabs.setZoomSettings().
661 scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function(
662 new TabsSetZoomSettingsFunction());
663 set_zoom_settings_function->set_extension(empty_extension.get());
664
665 // Test per-origin automatic zoom settings.
666 utils::RunFunction(set_zoom_function.get(),
667 base::StringPrintf("[%u, 1]", tab_id_B),
668 browser());
669 set_zoom_function = new TabsSetZoomFunction();
670 set_zoom_function->set_extension(empty_extension.get());
671 set_zoom_function->set_has_callback(true);
672 utils::RunFunction(set_zoom_function.get(),
673 base::StringPrintf("[%u, 1.1]", tab_id_A1),
674 browser());
675 EXPECT_EQ(1.1,
676 content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
677 EXPECT_EQ(1.1,
678 content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
679 EXPECT_EQ(1,
680 content::ZoomLevelToZoomFactor(web_contents_B->GetZoomLevel()));
681
682 // Test per-tab automatic zoom settings.
683 utils::RunFunction(set_zoom_settings_function.get(),
684 base::StringPrintf("[%u, {\"mode\": \"automatic\", "
685 "\"scope\": \"per-tab\"}]", tab_id_A1),
686 browser());
687 set_zoom_function = new TabsSetZoomFunction();
688 set_zoom_function->set_extension(empty_extension.get());
689 set_zoom_function->set_has_callback(true);
690 utils::RunFunction(set_zoom_function.get(),
691 base::StringPrintf("[%u, 1.2]", tab_id_A1),
692 browser());
693 EXPECT_EQ(1.2,
694 content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
695 EXPECT_EQ(1.1,
696 content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
697
698 // Test 'manual' mode.
699 set_zoom_settings_function = new TabsSetZoomSettingsFunction();
700 set_zoom_settings_function->set_extension(empty_extension.get());
701 utils::RunFunction(set_zoom_settings_function.get(),
702 base::StringPrintf("[%u, {\"mode\": \"manual\"}]",
703 tab_id_A1),
704 browser());
705 set_zoom_function = new TabsSetZoomFunction();
706 set_zoom_function->set_extension(empty_extension.get());
707 set_zoom_function->set_has_callback(true);
708 utils::RunFunction(set_zoom_function.get(),
709 base::StringPrintf("[%u, 1.3]", tab_id_A1),
710 browser());
711 EXPECT_EQ(1.3,
712 content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
713 EXPECT_EQ(1.1,
714 content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
715
716 // Test 'disabled' mode.
717 set_zoom_settings_function = new TabsSetZoomSettingsFunction();
718 set_zoom_settings_function->set_extension(empty_extension.get());
719 utils::RunFunction(set_zoom_settings_function.get(),
720 base::StringPrintf("[%u, {\"mode\": \"disabled\"}]",
721 tab_id_A1),
722 browser());
723 set_zoom_function = new TabsSetZoomFunction();
724 set_zoom_function->set_extension(empty_extension.get());
725 set_zoom_function->set_has_callback(true);
726 utils::RunFunction(set_zoom_function.get(),
727 base::StringPrintf("[%u, 1.4]", tab_id_A2),
728 browser());
729 EXPECT_EQ(1,
730 content::ZoomLevelToZoomFactor(web_contents_A1->GetZoomLevel()));
731 EXPECT_EQ(1.4,
732 content::ZoomLevelToZoomFactor(web_contents_A2->GetZoomLevel()));
733 }
734
735 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetZoomSettings) {
736 static const char kNewTestTabArgs[] = "about:blank";
737 content::OpenURLParams params(GURL(kNewTestTabArgs), content::Referrer(),
738 NEW_FOREGROUND_TAB,
739 content::PAGE_TRANSITION_LINK, false);
740 content::WebContents* web_contents = browser()->OpenURL(params);
741 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
742
743 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
744
745 // chrome.tabs.setZoomSettings().
746 scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function(
747 new TabsSetZoomSettingsFunction());
748 set_zoom_settings_function->set_extension(empty_extension.get());
749
750 // chrome.tabs.getZoomSettings().
751 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function(
752 new TabsGetZoomSettingsFunction());
753 get_zoom_settings_function->set_extension(empty_extension.get());
754 get_zoom_settings_function->set_has_callback(true);
755
756 utils::RunFunction(set_zoom_settings_function.get(),
757 base::StringPrintf("[%u, {\"mode\": \"automatic\", "
758 "\"scope\": \"per-tab\"}]", tab_id),
759 browser());
760 scoped_ptr<base::DictionaryValue> get_zoom_settings_result(
761 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
762 get_zoom_settings_function.get(), base::StringPrintf("[%u]", tab_id),
763 browser())));
764
765 std::string mode = utils::GetString(get_zoom_settings_result.get(), "mode");
766 std::string scope = utils::GetString(get_zoom_settings_result.get(), "scope");
767 EXPECT_EQ("automatic", mode);
768 EXPECT_EQ("per-tab", scope);
769 }
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.
770
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:
593 } // namespace extensions 771 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698