Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 void SetUpInProcessBrowserTestFixture() override { | 36 void SetUpInProcessBrowserTestFixture() override { |
| 37 // Start up the test server and get us ready for calling the install | 37 // Start up the test server and get us ready for calling the install |
| 38 // API functions. | 38 // API functions. |
| 39 host_resolver()->AddRule("www.cloudprintapp.com", "127.0.0.1"); | 39 host_resolver()->AddRule("www.cloudprintapp.com", "127.0.0.1"); |
| 40 ASSERT_TRUE(embedded_test_server()->Start()); | 40 ASSERT_TRUE(embedded_test_server()->Start()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 // Returns a test server URL, but with host 'www.cloudprintapp.com' so it | 44 // Returns a test server URL, but with host 'www.cloudprintapp.com' so it |
| 45 // matches the cloud print app's extent that we set up via command line | 45 // matches the cloud print app's extent that we set up via command line flags. |
| 46 // flags. | |
| 47 GURL GetTestServerURL(const std::string& path) { | 46 GURL GetTestServerURL(const std::string& path) { |
| 48 GURL url = embedded_test_server()->GetURL( | 47 GURL url = embedded_test_server()->GetURL( |
| 49 "/extensions/api_test/cloud_print_private/" + path); | 48 "/extensions/api_test/cloud_print_private/" + path); |
| 50 | 49 |
| 51 // Replace the host with 'www.cloudprintapp.com' so it matches the cloud | 50 // Replace the host with 'www.cloudprintapp.com' so it matches the cloud |
| 52 // print app's extent. | 51 // print app's extent. |
| 53 GURL::Replacements replace_host; | 52 GURL::Replacements replace_host; |
| 54 replace_host.SetHostStr("www.cloudprintapp.com"); | 53 replace_host.SetHostStr("www.cloudprintapp.com"); |
| 55 return url.ReplaceComponents(replace_host); | 54 return url.ReplaceComponents(replace_host); |
| 56 } | 55 } |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 #if !defined(OS_CHROMEOS) | 58 #if !defined(OS_CHROMEOS) |
| 60 | 59 |
| 61 using extensions::api::cloud_print_private::UserSettings; | 60 using extensions::api::cloud_print_private::UserSettings; |
| 62 | 61 |
| 63 class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate { | 62 class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate { |
| 64 public: | 63 public: |
| 65 CloudPrintTestsDelegateMock() {} | 64 CloudPrintTestsDelegateMock() {} |
|
Vitaly Buka (NO REVIEWS)
2016/04/21 20:09:45
why not just use the default destructor?
Lei Zhang
2016/04/21 20:50:22
Did you mean with " = default;" or leave it off?
| |
| 65 ~CloudPrintTestsDelegateMock() override {} | |
| 66 | 66 |
| 67 MOCK_METHOD4(SetupConnector, | 67 MOCK_METHOD4(SetupConnector, |
| 68 void(const std::string& user_email, | 68 void(const std::string& user_email, |
| 69 const std::string& robot_email, | 69 const std::string& robot_email, |
| 70 const std::string& credentials, | 70 const std::string& credentials, |
| 71 const UserSettings& user_settings)); | 71 const UserSettings& user_settings)); |
| 72 MOCK_METHOD0(GetHostName, std::string()); | 72 MOCK_METHOD0(GetHostName, std::string()); |
| 73 MOCK_METHOD0(GetPrinters, std::vector<std::string>()); | 73 MOCK_METHOD0(GetPrinters, std::vector<std::string>()); |
| 74 MOCK_METHOD0(GetClientId, std::string()); | 74 MOCK_METHOD0(GetClientId, std::string()); |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock); | 77 DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 MATCHER(IsExpectedUserSettings, "") { | 80 MATCHER(IsExpectedUserSettings, "") { |
| 81 const UserSettings& settings = arg; | 81 const UserSettings& settings = arg; |
| 82 return settings.connect_new_printers && settings.printers.size() == 2 && | 82 return settings.connect_new_printers && settings.printers.size() == 2 && |
| 83 settings.printers[0].name == "printer1" && | 83 settings.printers[0].name == "printer1" && |
| 84 !settings.printers[0].connect && | 84 !settings.printers[0].connect && |
| 85 settings.printers[1].name == "printer2" && | 85 settings.printers[1].name == "printer2" && |
| 86 settings.printers[1].connect; | 86 settings.printers[1].connect; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // http://crbug.com/177163 | 89 // http://crbug.com/177163 |
| 90 #if defined(OS_WIN) && !defined(NDEBUG) | 90 #if defined(OS_WIN) && !defined(NDEBUG) |
| 91 #define MAYBE_CloudPrintHosted DISABLED_CloudPrintHosted | 91 #define MAYBE_CloudPrintHostedWithMock DISABLED_CloudPrintHostedWithMock |
| 92 #else | 92 #else |
| 93 #define MAYBE_CloudPrintHosted CloudPrintHosted | 93 #define MAYBE_CloudPrintHostedWithMock CloudPrintHostedWithMock |
| 94 #endif | 94 #endif |
| 95 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, | 95 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, |
| 96 MAYBE_CloudPrintHosted) { | 96 MAYBE_CloudPrintHostedWithMock) { |
| 97 CloudPrintTestsDelegateMock cloud_print_mock; | 97 CloudPrintTestsDelegateMock cloud_print_mock; |
| 98 | 98 |
| 99 EXPECT_CALL(cloud_print_mock, | 99 EXPECT_CALL(cloud_print_mock, |
| 100 SetupConnector("foo@gmail.com", | 100 SetupConnector("foo@gmail.com", |
| 101 "foorobot@googleusercontent.com", | 101 "foorobot@googleusercontent.com", |
| 102 "1/23546efa54", | 102 "1/23546efa54", |
| 103 IsExpectedUserSettings())); | 103 IsExpectedUserSettings())); |
| 104 EXPECT_CALL(cloud_print_mock, GetHostName()) | 104 EXPECT_CALL(cloud_print_mock, GetHostName()) |
| 105 .WillRepeatedly(Return("TestHostName")); | 105 .WillRepeatedly(Return("TestHostName")); |
| 106 | 106 |
| 107 std::vector<std::string> printers; | 107 std::vector<std::string> printers; |
| 108 printers.push_back("printer1"); | 108 printers.push_back("printer1"); |
| 109 printers.push_back("printer2"); | 109 printers.push_back("printer2"); |
| 110 EXPECT_CALL(cloud_print_mock, GetPrinters()) | 110 EXPECT_CALL(cloud_print_mock, GetPrinters()) |
| 111 .WillRepeatedly(Return(printers)); | 111 .WillRepeatedly(Return(printers)); |
| 112 | 112 |
| 113 EXPECT_CALL(cloud_print_mock, GetClientId()) | 113 EXPECT_CALL(cloud_print_mock, GetClientId()) |
| 114 .WillRepeatedly(Return("TestAPIClient")); | 114 .WillRepeatedly(Return("TestAPIClient")); |
| 115 | 115 |
| 116 // Run this as a hosted app. Since we have overridden the cloud print service | 116 // Run this as a hosted app. Since we have overridden the cloud print service |
| 117 // URL in the command line, this URL should match the web extent for our | 117 // URL in the command line, this URL should match the web extent for our |
| 118 // cloud print component app and it should work. | 118 // cloud print component app and it should work. |
| 119 GURL page_url = GetTestServerURL( | 119 GURL page_url = GetTestServerURL( |
| 120 "enable_chrome_connector/cloud_print_success_tests.html"); | 120 "enable_chrome_connector/cloud_print_success_tests.html"); |
| 121 ASSERT_TRUE(RunPageTest(page_url.spec())); | 121 ASSERT_TRUE(RunPageTest(page_url.spec())); |
| 122 } | 122 } |
| 123 | 123 |
| 124 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, | |
| 125 CloudPrintHostedIncognito) { | |
| 126 GURL page_url = GetTestServerURL( | |
| 127 "enable_chrome_connector/cloud_print_incognito_failure_tests.html"); | |
| 128 ASSERT_TRUE(RunPageTest(page_url.spec(), kFlagUseIncognito)); | |
| 129 } | |
| 130 | |
| 124 #endif // !defined(OS_CHROMEOS) | 131 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |