Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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/extension_apitest.h" | |
| 7 #include "chrome/browser/extensions/extension_chrome_auth_private_api.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/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 std::string("files/extensions/api_test/chrome_auth_private/") + path); | |
|
Matt Perry
2011/06/24 19:11:09
fyi, "foo" + path should work since path is a std:
sanjeevr
2011/06/24 22:38:48
Done. I had copied this from the webstore tests.
| |
| 38 | |
| 39 // Replace the host with 'www.example.com' so it matches the web store | |
|
Matt Perry
2011/06/24 19:11:09
comment doesn't match
sanjeevr
2011/06/24 22:38:48
Done.
| |
| 40 // 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 IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, | |
| 49 SetCloudPrintCredentialsSuccessHosted) { | |
| 50 // Run this as a hosted app. Since we have overridden the cloud print service | |
| 51 // URL in the command line, this URL should match the web extent for our | |
| 52 // cloud print component app and it should work. | |
| 53 SetCloudPrintCredentialsFunction::SetTestMode(true); | |
| 54 GURL page_url = GetTestServerURL( | |
| 55 "enable_chrome_connector/cloud_print_success_tests.html"); | |
| 56 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
| 57 } | |
| 58 | |
| 59 IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, | |
| 60 SetCloudPrintCredentialsFailureInstalled) { | |
| 61 // Run this as an installed app. Since this is not a component app, it | |
| 62 // should fail. | |
| 63 ASSERT_TRUE(RunExtensionTest("chrome_auth_private/installed_app")); | |
| 64 } | |
| 65 | |
| 66 IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, | |
| 67 SetCloudPrintCredentialsFailureInstalledComponent) { | |
| 68 // Run this as an installed component app. This should also fail because of | |
| 69 // the explicit URL check in the API. | |
| 70 ASSERT_TRUE(RunComponentExtensionTest( | |
| 71 "chrome_auth_private/installed_component_app")); | |
| 72 } | |
| 73 | |
| OLD | NEW |