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