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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 501263002: Remove implicit conversions from scoped_refptr to T* in chrome/browser/extensions/api/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Just in case Created 6 years, 3 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
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"
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 }; 629 };
630 630
631 void ExtensionTabsZoomTest::SetUpOnMainThread() { 631 void ExtensionTabsZoomTest::SetUpOnMainThread() {
632 ExtensionTabsTest::SetUpOnMainThread(); 632 ExtensionTabsTest::SetUpOnMainThread();
633 extension_ = utils::CreateEmptyExtension(); 633 extension_ = utils::CreateEmptyExtension();
634 } 634 }
635 635
636 bool ExtensionTabsZoomTest::RunSetZoom(int tab_id, double zoom_factor) { 636 bool ExtensionTabsZoomTest::RunSetZoom(int tab_id, double zoom_factor) {
637 scoped_refptr<TabsSetZoomFunction> set_zoom_function( 637 scoped_refptr<TabsSetZoomFunction> set_zoom_function(
638 new TabsSetZoomFunction()); 638 new TabsSetZoomFunction());
639 set_zoom_function->set_extension(extension_); 639 set_zoom_function->set_extension(extension_.get());
640 set_zoom_function->set_has_callback(true); 640 set_zoom_function->set_has_callback(true);
641 641
642 return utils::RunFunction( 642 return utils::RunFunction(
643 set_zoom_function.get(), 643 set_zoom_function.get(),
644 base::StringPrintf("[%u, %lf]", tab_id, zoom_factor), 644 base::StringPrintf("[%u, %lf]", tab_id, zoom_factor),
645 browser(), 645 browser(),
646 extension_function_test_utils::NONE); 646 extension_function_test_utils::NONE);
647 } 647 }
648 648
649 testing::AssertionResult ExtensionTabsZoomTest::RunGetZoom( 649 testing::AssertionResult ExtensionTabsZoomTest::RunGetZoom(
650 int tab_id, 650 int tab_id,
651 double* zoom_factor) { 651 double* zoom_factor) {
652 scoped_refptr<TabsGetZoomFunction> get_zoom_function( 652 scoped_refptr<TabsGetZoomFunction> get_zoom_function(
653 new TabsGetZoomFunction()); 653 new TabsGetZoomFunction());
654 get_zoom_function->set_extension(extension_); 654 get_zoom_function->set_extension(extension_.get());
655 get_zoom_function->set_has_callback(true); 655 get_zoom_function->set_has_callback(true);
656 656
657 scoped_ptr<base::Value> get_zoom_result( 657 scoped_ptr<base::Value> get_zoom_result(
658 utils::RunFunctionAndReturnSingleResult( 658 utils::RunFunctionAndReturnSingleResult(
659 get_zoom_function.get(), 659 get_zoom_function.get(),
660 base::StringPrintf("[%u]", tab_id), 660 base::StringPrintf("[%u]", tab_id),
661 browser())); 661 browser()));
662 662
663 if (!get_zoom_result) 663 if (!get_zoom_result)
664 return testing::AssertionFailure() << "no result"; 664 return testing::AssertionFailure() << "no result";
665 if (!get_zoom_result->GetAsDouble(zoom_factor)) 665 if (!get_zoom_result->GetAsDouble(zoom_factor))
666 return testing::AssertionFailure() << "result was not a double"; 666 return testing::AssertionFailure() << "result was not a double";
667 667
668 return testing::AssertionSuccess(); 668 return testing::AssertionSuccess();
669 } 669 }
670 670
671 bool ExtensionTabsZoomTest::RunSetZoomSettings(int tab_id, 671 bool ExtensionTabsZoomTest::RunSetZoomSettings(int tab_id,
672 const char* mode, 672 const char* mode,
673 const char* scope) { 673 const char* scope) {
674 scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function( 674 scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function(
675 new TabsSetZoomSettingsFunction()); 675 new TabsSetZoomSettingsFunction());
676 set_zoom_settings_function->set_extension(extension_); 676 set_zoom_settings_function->set_extension(extension_.get());
677 677
678 std::string args; 678 std::string args;
679 if (scope) { 679 if (scope) {
680 args = base::StringPrintf("[%u, {\"mode\": \"%s\", \"scope\": \"%s\"}]", 680 args = base::StringPrintf("[%u, {\"mode\": \"%s\", \"scope\": \"%s\"}]",
681 tab_id, mode, scope); 681 tab_id, mode, scope);
682 } else { 682 } else {
683 args = base::StringPrintf("[%u, {\"mode\": \"%s\"}]", tab_id, mode); 683 args = base::StringPrintf("[%u, {\"mode\": \"%s\"}]", tab_id, mode);
684 } 684 }
685 685
686 return utils::RunFunction(set_zoom_settings_function.get(), 686 return utils::RunFunction(set_zoom_settings_function.get(),
687 args, 687 args,
688 browser(), 688 browser(),
689 extension_function_test_utils::NONE); 689 extension_function_test_utils::NONE);
690 } 690 }
691 691
692 testing::AssertionResult ExtensionTabsZoomTest::RunGetZoomSettings( 692 testing::AssertionResult ExtensionTabsZoomTest::RunGetZoomSettings(
693 int tab_id, 693 int tab_id,
694 std::string* mode, 694 std::string* mode,
695 std::string* scope) { 695 std::string* scope) {
696 DCHECK(mode); 696 DCHECK(mode);
697 DCHECK(scope); 697 DCHECK(scope);
698 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function( 698 scoped_refptr<TabsGetZoomSettingsFunction> get_zoom_settings_function(
699 new TabsGetZoomSettingsFunction()); 699 new TabsGetZoomSettingsFunction());
700 get_zoom_settings_function->set_extension(extension_); 700 get_zoom_settings_function->set_extension(extension_.get());
701 get_zoom_settings_function->set_has_callback(true); 701 get_zoom_settings_function->set_has_callback(true);
702 702
703 scoped_ptr<base::DictionaryValue> get_zoom_settings_result( 703 scoped_ptr<base::DictionaryValue> get_zoom_settings_result(
704 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult( 704 utils::ToDictionary(utils::RunFunctionAndReturnSingleResult(
705 get_zoom_settings_function.get(), 705 get_zoom_settings_function.get(),
706 base::StringPrintf("[%u]", tab_id), 706 base::StringPrintf("[%u]", tab_id),
707 browser()))); 707 browser())));
708 708
709 if (!get_zoom_settings_result) 709 if (!get_zoom_settings_result)
710 return testing::AssertionFailure() << "no result"; 710 return testing::AssertionFailure() << "no result";
711 711
712 *mode = utils::GetString(get_zoom_settings_result.get(), "mode"); 712 *mode = utils::GetString(get_zoom_settings_result.get(), "mode");
713 *scope = utils::GetString(get_zoom_settings_result.get(), "scope"); 713 *scope = utils::GetString(get_zoom_settings_result.get(), "scope");
714 714
715 return testing::AssertionSuccess(); 715 return testing::AssertionSuccess();
716 } 716 }
717 717
718 std::string ExtensionTabsZoomTest::RunSetZoomExpectError(int tab_id, 718 std::string ExtensionTabsZoomTest::RunSetZoomExpectError(int tab_id,
719 double zoom_factor) { 719 double zoom_factor) {
720 scoped_refptr<TabsSetZoomFunction> set_zoom_function( 720 scoped_refptr<TabsSetZoomFunction> set_zoom_function(
721 new TabsSetZoomFunction()); 721 new TabsSetZoomFunction());
722 set_zoom_function->set_extension(extension_); 722 set_zoom_function->set_extension(extension_.get());
723 set_zoom_function->set_has_callback(true); 723 set_zoom_function->set_has_callback(true);
724 724
725 return utils::RunFunctionAndReturnError( 725 return utils::RunFunctionAndReturnError(
726 set_zoom_function.get(), 726 set_zoom_function.get(),
727 base::StringPrintf("[%u, %lf]", tab_id, zoom_factor), 727 base::StringPrintf("[%u, %lf]", tab_id, zoom_factor),
728 browser()); 728 browser());
729 } 729 }
730 730
731 std::string ExtensionTabsZoomTest::RunSetZoomSettingsExpectError( 731 std::string ExtensionTabsZoomTest::RunSetZoomSettingsExpectError(
732 int tab_id, 732 int tab_id,
733 const char* mode, 733 const char* mode,
734 const char* scope) { 734 const char* scope) {
735 scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function( 735 scoped_refptr<TabsSetZoomSettingsFunction> set_zoom_settings_function(
736 new TabsSetZoomSettingsFunction()); 736 new TabsSetZoomSettingsFunction());
737 set_zoom_settings_function->set_extension(extension_); 737 set_zoom_settings_function->set_extension(extension_.get());
738 738
739 return utils::RunFunctionAndReturnError(set_zoom_settings_function.get(), 739 return utils::RunFunctionAndReturnError(set_zoom_settings_function.get(),
740 base::StringPrintf( 740 base::StringPrintf(
741 "[%u, {\"mode\": \"%s\", " 741 "[%u, {\"mode\": \"%s\", "
742 "\"scope\": \"%s\"}]", 742 "\"scope\": \"%s\"}]",
743 tab_id, 743 tab_id,
744 mode, 744 mode,
745 scope), 745 scope),
746 browser()); 746 browser());
747 } 747 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // Test chrome.tabs.setZoom(). 904 // Test chrome.tabs.setZoom().
905 error = RunSetZoomExpectError(tab_id, 3.14159); 905 error = RunSetZoomExpectError(tab_id, 3.14159);
906 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 906 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
907 907
908 // chrome.tabs.setZoomSettings(). 908 // chrome.tabs.setZoomSettings().
909 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab"); 909 error = RunSetZoomSettingsExpectError(tab_id, "manual", "per-tab");
910 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl)); 910 EXPECT_TRUE(MatchPattern(error, manifest_errors::kCannotAccessChromeUrl));
911 } 911 }
912 912
913 } // namespace extensions 913 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698