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

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,
63 void(const std::string& user_email,
64 const std::string& robot_email,
65 const std::string& credentials,
66 bool connect_new_printers,
67 const std::vector<std::string>& printer_blacklist));
68 MOCK_METHOD0(GetHostName, std::string());
69 MOCK_METHOD0(GetPrinters, std::vector<std::string>());
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock);
73 };
74
75 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, CloudPrintHosted) {
76 CloudPrintTestsDelegateMock cloud_print_mock;
77 std::vector<std::string> printers;
78 printers.push_back("printer1");
79 printers.push_back("printer2");
80
81 EXPECT_CALL(cloud_print_mock,
82 SetupConnector("foo@gmail.com",
83 "foorobot@googleusercontent.com",
84 "1/23546efa54",
85 true,
86 printers));
87 EXPECT_CALL(cloud_print_mock, GetHostName())
88 .WillRepeatedly(Return("TestHostName"));
89 EXPECT_CALL(cloud_print_mock, GetPrinters())
90 .WillRepeatedly(Return(printers));
51 // Run this as a hosted app. Since we have overridden the cloud print service 91 // 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 92 // URL in the command line, this URL should match the web extent for our
53 // cloud print component app and it should work. 93 // cloud print component app and it should work.
54 extensions::CloudPrintSetCredentialsFunction::SetTestMode(true);
55 GURL page_url = GetTestServerURL( 94 GURL page_url = GetTestServerURL(
56 "enable_chrome_connector/cloud_print_success_tests.html"); 95 "enable_chrome_connector/cloud_print_success_tests.html");
57 ASSERT_TRUE(RunPageTest(page_url.spec())); 96 ASSERT_TRUE(RunPageTest(page_url.spec()));
58 extensions::CloudPrintSetCredentialsFunction::SetTestMode(false);
59 } 97 }
98
60 #endif // !defined(OS_CHROMEOS) 99 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698