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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "chrome/browser/extensions/api/chrome_auth_private/chrome_auth_private_
api.h" | 6 #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_
api.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
12 #include "net/base/mock_host_resolver.h" | 12 #include "net/base/mock_host_resolver.h" |
13 | 13 |
14 // A base class for tests below. | 14 // A base class for tests below. |
15 class ExtensionChromeAuthPrivateApiTest : public ExtensionApiTest { | 15 class ExtensionCloudPrintPrivateApiTest : public ExtensionApiTest { |
16 public: | 16 public: |
17 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 17 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
18 ExtensionApiTest::SetUpCommandLine(command_line); | 18 ExtensionApiTest::SetUpCommandLine(command_line); |
19 command_line->AppendSwitchASCII(switches::kCloudPrintServiceURL, | 19 command_line->AppendSwitchASCII(switches::kCloudPrintServiceURL, |
20 "http://www.cloudprintapp.com/files/extensions/api_test/" | 20 "http://www.cloudprintapp.com/files/extensions/api_test/" |
21 "chrome_auth_private"); | 21 "cloud_print_private"); |
22 } | 22 } |
23 | 23 |
24 void SetUpInProcessBrowserTestFixture() OVERRIDE { | 24 void SetUpInProcessBrowserTestFixture() OVERRIDE { |
25 // Start up the test server and get us ready for calling the install | 25 // Start up the test server and get us ready for calling the install |
26 // API functions. | 26 // API functions. |
27 host_resolver()->AddRule("www.cloudprintapp.com", "127.0.0.1"); | 27 host_resolver()->AddRule("www.cloudprintapp.com", "127.0.0.1"); |
28 ASSERT_TRUE(test_server()->Start()); | 28 ASSERT_TRUE(test_server()->Start()); |
29 } | 29 } |
30 | 30 |
31 protected: | 31 protected: |
32 // Returns a test server URL, but with host 'www.cloudprintapp.com' so it | 32 // Returns a test server URL, but with host 'www.cloudprintapp.com' so it |
33 // matches the cloud print app's extent that we set up via command line | 33 // matches the cloud print app's extent that we set up via command line |
34 // flags. | 34 // flags. |
35 GURL GetTestServerURL(const std::string& path) { | 35 GURL GetTestServerURL(const std::string& path) { |
36 GURL url = test_server()->GetURL( | 36 GURL url = test_server()->GetURL( |
37 "files/extensions/api_test/chrome_auth_private/" + path); | 37 "files/extensions/api_test/cloud_print_private/" + path); |
38 | 38 |
39 // Replace the host with 'www.cloudprintapp.com' so it matches the cloud | 39 // Replace the host with 'www.cloudprintapp.com' so it matches the cloud |
40 // print app's extent. | 40 // print app's extent. |
41 GURL::Replacements replace_host; | 41 GURL::Replacements replace_host; |
42 std::string host_str("www.cloudprintapp.com"); | 42 std::string host_str("www.cloudprintapp.com"); |
43 replace_host.SetHostStr(host_str); | 43 replace_host.SetHostStr(host_str); |
44 return url.ReplaceComponents(replace_host); | 44 return url.ReplaceComponents(replace_host); |
45 } | 45 } |
46 }; | 46 }; |
47 | 47 |
48 #if !defined(OS_CHROMEOS) | 48 #if !defined(OS_CHROMEOS) |
49 IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, | 49 IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, |
50 SetCloudPrintCredentialsSuccessHosted) { | 50 CloudPrintSetCredentialsSuccessHosted) { |
51 // Run this as a hosted app. Since we have overridden the cloud print service | 51 // 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 | 52 // URL in the command line, this URL should match the web extent for our |
53 // cloud print component app and it should work. | 53 // cloud print component app and it should work. |
54 extensions::SetCloudPrintCredentialsFunction::SetTestMode(true); | 54 extensions::CloudPrintSetCredentialsFunction::SetTestMode(true); |
55 GURL page_url = GetTestServerURL( | 55 GURL page_url = GetTestServerURL( |
56 "enable_chrome_connector/cloud_print_success_tests.html"); | 56 "enable_chrome_connector/cloud_print_success_tests.html"); |
57 ASSERT_TRUE(RunPageTest(page_url.spec())); | 57 ASSERT_TRUE(RunPageTest(page_url.spec())); |
58 extensions::SetCloudPrintCredentialsFunction::SetTestMode(false); | 58 extensions::CloudPrintSetCredentialsFunction::SetTestMode(false); |
59 } | 59 } |
60 #endif // !defined(OS_CHROMEOS) | 60 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |