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

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

Issue 11037005: New Cloud Print Private API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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"
6
5 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
6 #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_ api.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
12 #include "net/base/mock_host_resolver.h" 13 #include "net/base/mock_host_resolver.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using ::testing::Eq;
18 using ::testing::Property;
19 using ::testing::Return;
20 using ::testing::_;
13 21
14 // A base class for tests below. 22 // A base class for tests below.
15 class ExtensionCloudPrintPrivateApiTest : public ExtensionApiTest { 23 class ExtensionCloudPrintPrivateApiTest : public ExtensionApiTest {
16 public: 24 public:
17 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 25 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
18 ExtensionApiTest::SetUpCommandLine(command_line); 26 ExtensionApiTest::SetUpCommandLine(command_line);
19 command_line->AppendSwitchASCII(switches::kCloudPrintServiceURL, 27 command_line->AppendSwitchASCII(switches::kCloudPrintServiceURL,
20 "http://www.cloudprintapp.com/files/extensions/api_test/" 28 "http://www.cloudprintapp.com/files/extensions/api_test/"
21 "cloud_print_private"); 29 "cloud_print_private");
22 } 30 }
(...skipping 16 matching lines...) Expand all
39 // Replace the host with 'www.cloudprintapp.com' so it matches the cloud 47 // Replace the host with 'www.cloudprintapp.com' so it matches the cloud
40 // print app's extent. 48 // print app's extent.
41 GURL::Replacements replace_host; 49 GURL::Replacements replace_host;
42 std::string host_str("www.cloudprintapp.com"); 50 std::string host_str("www.cloudprintapp.com");
43 replace_host.SetHostStr(host_str); 51 replace_host.SetHostStr(host_str);
44 return url.ReplaceComponents(replace_host); 52 return url.ReplaceComponents(replace_host);
45 } 53 }
46 }; 54 };
47 55
48 #if !defined(OS_CHROMEOS) 56 #if !defined(OS_CHROMEOS)
49 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, 57
50 CloudPrintSetCredentialsSuccessHosted) { 58 class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate {
59 public:
60 CloudPrintTestsDelegateMock() {}
61
62 MOCK_METHOD5(SetupConnector, void(const std::string& user_email,
63 const std::string& robot_email,
64 const std::string& credentials,
65 bool connect_new_printers,
66 const base::ListValue* printer_blacklist));
67 MOCK_METHOD0(GetHostName, std::string());
68 MOCK_METHOD0(GetPrinters, std::vector<std::string>());
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock);
72 };
73
74 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, CloudPrintHosted) {
75 CloudPrintTestsDelegateMock cloud_print_mock;
76 EXPECT_CALL(cloud_print_mock,
77 SetupConnector("foo@gmail.com",
78 "foorobot@googleusercontent.com",
79 "1/23546efa54",
80 true,
81 Property(&base::ListValue::GetSize, Eq(2u))));
82 EXPECT_CALL(cloud_print_mock, GetHostName())
83 .WillRepeatedly(Return("TestHostName"));
84 std::vector<std::string> printers;
85 printers.push_back("printer1");
86 printers.push_back("printer2");
87 EXPECT_CALL(cloud_print_mock, GetPrinters())
88 .WillRepeatedly(Return(printers));
51 // Run this as a hosted app. Since we have overridden the cloud print service 89 // Run this as a hosted app. Since we have overridden the cloud print service
52 // URL in the command line, this URL should match the web extent for our 90 // URL in the command line, this URL should match the web extent for our
53 // cloud print component app and it should work. 91 // cloud print component app and it should work.
54 extensions::CloudPrintSetCredentialsFunction::SetTestMode(true);
55 GURL page_url = GetTestServerURL( 92 GURL page_url = GetTestServerURL(
56 "enable_chrome_connector/cloud_print_success_tests.html"); 93 "enable_chrome_connector/cloud_print_success_tests.html");
57 ASSERT_TRUE(RunPageTest(page_url.spec())); 94 ASSERT_TRUE(RunPageTest(page_url.spec()));
58 extensions::CloudPrintSetCredentialsFunction::SetTestMode(false);
59 } 95 }
96
60 #endif // !defined(OS_CHROMEOS) 97 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698