| 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         "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 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   SetCloudPrintCredentialsFunction::SetTestMode(false); | 
 |  58 } | 
 |  59  | 
 |  60 IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, | 
 |  61                        SetCloudPrintCredentialsFailureInstalled) { | 
 |  62   // Run this as an installed app. Since this is not a component app, it | 
 |  63   // should fail. | 
 |  64   ASSERT_TRUE(RunExtensionTest("chrome_auth_private/installed_app")); | 
 |  65 } | 
 |  66  | 
 |  67 IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, | 
 |  68                        SetCloudPrintCredentialsFailureInstalledComponent) { | 
 |  69   // Run this as an installed component app. This should also fail because of | 
 |  70   // the explicit URL check in the API. | 
 |  71   ASSERT_TRUE(RunComponentExtensionTest( | 
 |  72       "chrome_auth_private/installed_component_app")); | 
 |  73 } | 
 |  74  | 
| OLD | NEW |