Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 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" |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 6 | #if defined (OS_WIN) |
| 7 | #include "base/win/windows_version.h" |
| 8 | #endif // defined (OS_WIN) |
| 9 | |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_apitest.h" |
| 11 | #include "chrome/browser/extensions/extension_webstore_private_api.h" |
| 12 | #include "chrome/common/chrome_switches.h" |
| 13 | #include "chrome/test/ui_test_utils.h" |
| 14 | #include "net/base/mock_host_resolver.h" |
| 15 | |
| 16 | class ExtensionGalleryInstallApiTest : public ExtensionApiTest { |
| 17 | public: |
| 18 | void SetUpCommandLine(CommandLine* command_line) { |
| 19 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 20 | command_line->AppendSwitchASCII(switches::kAppsGalleryURL, |
| 21 | "http://www.example.com"); |
| 22 | } |
Ben Murdoch | 4a5e2dc | 2010-11-25 19:40:10 +0000 | [diff] [blame] | 23 | |
| 24 | bool RunInstallTest(const std::string& page) { |
| 25 | std::string base_url = base::StringPrintf( |
| 26 | "http://www.example.com:%u/files/extensions/", |
| 27 | test_server()->host_port_pair().port()); |
| 28 | |
| 29 | std::string testing_install_base_url = base_url; |
| 30 | testing_install_base_url += "good.crx"; |
Ben Murdoch | 201ade2 | 2011-01-07 14:18:56 +0000 | [diff] [blame] | 31 | |
| 32 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 33 | switches::kAppsGalleryUpdateURL, testing_install_base_url); |
Ben Murdoch | 4a5e2dc | 2010-11-25 19:40:10 +0000 | [diff] [blame] | 34 | |
| 35 | std::string page_url = base_url; |
| 36 | page_url += "api_test/extension_gallery_install/" + page; |
| 37 | |
| 38 | return RunPageTest(page_url.c_str()); |
| 39 | } |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | bool RunningOnXP() { |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 45 | #if defined (OS_WIN) |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 46 | return GetVersion() < base::win::VERSION_VISTA; |
| 47 | #else |
| 48 | return false; |
| 49 | #endif // defined (OS_WIN) |
| 50 | } |
| 51 | |
| 52 | } // namespace |
| 53 | |
| 54 | // TODO(asargent) - for some reason this test occasionally fails on XP, |
| 55 | // but not other versions of windows. http://crbug.com/55642 |
| 56 | #if defined (OS_WIN) |
| 57 | #define MAYBE_InstallAndUninstall FLAKY_InstallAndUninstall |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 58 | #else |
| 59 | #define MAYBE_InstallAndUninstall InstallAndUninstall |
| 60 | #endif |
| 61 | IN_PROC_BROWSER_TEST_F(ExtensionGalleryInstallApiTest, |
| 62 | MAYBE_InstallAndUninstall) { |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 63 | if (RunningOnXP()) { |
| 64 | LOG(INFO) << "Adding host resolver rule"; |
| 65 | } |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 66 | host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 67 | if (RunningOnXP()) { |
| 68 | LOG(INFO) << "Starting test server"; |
| 69 | } |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 70 | ASSERT_TRUE(test_server()->Start()); |
| 71 | |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 72 | if (RunningOnXP()) { |
| 73 | LOG(INFO) << "Starting tests without user gesture checking"; |
| 74 | } |
Ben Murdoch | 4a5e2dc | 2010-11-25 19:40:10 +0000 | [diff] [blame] | 75 | BeginInstallFunction::SetIgnoreUserGestureForTests(true); |
| 76 | ASSERT_TRUE(RunInstallTest("test.html")); |
| 77 | ASSERT_TRUE(RunInstallTest("complete_without_begin.html")); |
| 78 | ASSERT_TRUE(RunInstallTest("invalid_begin.html")); |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 79 | |
Kristian Monsen | ddb351d | 2011-06-28 21:49:31 +0100 | [diff] [blame] | 80 | if (RunningOnXP()) { |
| 81 | LOG(INFO) << "Starting tests with user gesture checking"; |
| 82 | } |
Ben Murdoch | 4a5e2dc | 2010-11-25 19:40:10 +0000 | [diff] [blame] | 83 | BeginInstallFunction::SetIgnoreUserGestureForTests(false); |
| 84 | ASSERT_TRUE(RunInstallTest("no_user_gesture.html")); |
Kristian Monsen | bda42a8 | 2010-10-27 13:27:14 +0100 | [diff] [blame] | 85 | } |