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

Side by Side Diff: chrome/browser/extensions/api/cloud_print_private/cloud_print_private_apitest.cc

Issue 14215009: Changed cloud print private API to pass all page settings as single object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_ api.h" 5 #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_ api.h"
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/api/cloud_print_private.h"
12 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
13 #include "net/dns/mock_host_resolver.h" 14 #include "net/dns/mock_host_resolver.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using ::testing::Eq; 18 using ::testing::Eq;
18 using ::testing::Property; 19 using ::testing::Property;
19 using ::testing::Return; 20 using ::testing::Return;
20 using ::testing::_; 21 using ::testing::_;
21 22
(...skipping 26 matching lines...) Expand all
48 // print app's extent. 49 // print app's extent.
49 GURL::Replacements replace_host; 50 GURL::Replacements replace_host;
50 std::string host_str("www.cloudprintapp.com"); 51 std::string host_str("www.cloudprintapp.com");
51 replace_host.SetHostStr(host_str); 52 replace_host.SetHostStr(host_str);
52 return url.ReplaceComponents(replace_host); 53 return url.ReplaceComponents(replace_host);
53 } 54 }
54 }; 55 };
55 56
56 #if !defined(OS_CHROMEOS) 57 #if !defined(OS_CHROMEOS)
57 58
59 using extensions::api::cloud_print_private::UserSettings;
60
58 class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate { 61 class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate {
59 public: 62 public:
60 CloudPrintTestsDelegateMock() {} 63 CloudPrintTestsDelegateMock() {}
61 64
62 MOCK_METHOD5(SetupConnector, 65 MOCK_METHOD4(SetupConnector,
63 void(const std::string& user_email, 66 void(const std::string& user_email,
64 const std::string& robot_email, 67 const std::string& robot_email,
65 const std::string& credentials, 68 const std::string& credentials,
66 bool connect_new_printers, 69 const UserSettings& user_settings));
67 const std::vector<std::string>& printer_blacklist));
68 MOCK_METHOD0(GetHostName, std::string()); 70 MOCK_METHOD0(GetHostName, std::string());
69 MOCK_METHOD0(GetPrinters, std::vector<std::string>()); 71 MOCK_METHOD0(GetPrinters, std::vector<std::string>());
70 MOCK_METHOD0(GetClientId, std::string()); 72 MOCK_METHOD0(GetClientId, std::string());
73
71 private: 74 private:
72 DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock); 75 DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock);
73 }; 76 };
74 77
78 MATCHER(IsExpectedUserSettings, "") {
79 const UserSettings& settings = arg;
80 return settings.connect_new_printers &&
81 settings.printers.size() == 2 &&
82 settings.printers[0]->name == "printer1" &&
83 !settings.printers[0]->connect &&
84 settings.printers[1]->name == "printer2" &&
85 settings.printers[1]->connect;
86 }
87
75 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, CloudPrintHosted) { 88 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, CloudPrintHosted) {
76 CloudPrintTestsDelegateMock cloud_print_mock; 89 CloudPrintTestsDelegateMock cloud_print_mock;
77 std::vector<std::string> printers;
78 printers.push_back("printer1");
79 printers.push_back("printer2");
80 90
81 EXPECT_CALL(cloud_print_mock, 91 EXPECT_CALL(cloud_print_mock,
82 SetupConnector("foo@gmail.com", 92 SetupConnector("foo@gmail.com",
83 "foorobot@googleusercontent.com", 93 "foorobot@googleusercontent.com",
84 "1/23546efa54", 94 "1/23546efa54",
85 true, 95 IsExpectedUserSettings()));
86 printers));
87 EXPECT_CALL(cloud_print_mock, GetHostName()) 96 EXPECT_CALL(cloud_print_mock, GetHostName())
88 .WillRepeatedly(Return("TestHostName")); 97 .WillRepeatedly(Return("TestHostName"));
98
99 std::vector<std::string> printers;
100 printers.push_back("printer1");
101 printers.push_back("printer2");
89 EXPECT_CALL(cloud_print_mock, GetPrinters()) 102 EXPECT_CALL(cloud_print_mock, GetPrinters())
90 .WillRepeatedly(Return(printers)); 103 .WillRepeatedly(Return(printers));
91 104
92 EXPECT_CALL(cloud_print_mock, GetClientId()) 105 EXPECT_CALL(cloud_print_mock, GetClientId())
93 .WillRepeatedly(Return("TestAPIClient")); 106 .WillRepeatedly(Return("TestAPIClient"));
94 107
95 // Run this as a hosted app. Since we have overridden the cloud print service 108 // Run this as a hosted app. Since we have overridden the cloud print service
96 // URL in the command line, this URL should match the web extent for our 109 // URL in the command line, this URL should match the web extent for our
97 // cloud print component app and it should work. 110 // cloud print component app and it should work.
98 GURL page_url = GetTestServerURL( 111 GURL page_url = GetTestServerURL(
99 "enable_chrome_connector/cloud_print_success_tests.html"); 112 "enable_chrome_connector/cloud_print_success_tests.html");
100 ASSERT_TRUE(RunPageTest(page_url.spec())); 113 ASSERT_TRUE(RunPageTest(page_url.spec()));
101 } 114 }
102 115
103 #endif // !defined(OS_CHROMEOS) 116 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698