blob: efb11f1c2015e2fbe3b770c0688bd555a98a6054 [file] [log] [blame]
Kristian Monsenddb351d2011-06-28 21:49:31 +01001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
Kristian Monsenbda42a82010-10-27 13:27:14 +01002// 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 Monsenddb351d2011-06-28 21:49:31 +01006#if defined (OS_WIN)
7#include "base/win/windows_version.h"
8#endif // defined (OS_WIN)
9
Kristian Monsenbda42a82010-10-27 13:27:14 +010010#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
16class 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 Murdoch4a5e2dc2010-11-25 19:40:10 +000023
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 Murdoch201ade22011-01-07 14:18:56 +000031
32 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
33 switches::kAppsGalleryUpdateURL, testing_install_base_url);
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000034
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 Monsenbda42a82010-10-27 13:27:14 +010040};
41
Kristian Monsenddb351d2011-06-28 21:49:31 +010042namespace {
43
44bool RunningOnXP() {
Kristian Monsenbda42a82010-10-27 13:27:14 +010045#if defined (OS_WIN)
Kristian Monsenddb351d2011-06-28 21:49:31 +010046 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 Monsenbda42a82010-10-27 13:27:14 +010058#else
59#define MAYBE_InstallAndUninstall InstallAndUninstall
60#endif
61IN_PROC_BROWSER_TEST_F(ExtensionGalleryInstallApiTest,
62 MAYBE_InstallAndUninstall) {
Kristian Monsenddb351d2011-06-28 21:49:31 +010063 if (RunningOnXP()) {
64 LOG(INFO) << "Adding host resolver rule";
65 }
Kristian Monsenbda42a82010-10-27 13:27:14 +010066 host_resolver()->AddRule("www.example.com", "127.0.0.1");
Kristian Monsenddb351d2011-06-28 21:49:31 +010067 if (RunningOnXP()) {
68 LOG(INFO) << "Starting test server";
69 }
Kristian Monsenbda42a82010-10-27 13:27:14 +010070 ASSERT_TRUE(test_server()->Start());
71
Kristian Monsenddb351d2011-06-28 21:49:31 +010072 if (RunningOnXP()) {
73 LOG(INFO) << "Starting tests without user gesture checking";
74 }
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000075 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 Monsenbda42a82010-10-27 13:27:14 +010079
Kristian Monsenddb351d2011-06-28 21:49:31 +010080 if (RunningOnXP()) {
81 LOG(INFO) << "Starting tests with user gesture checking";
82 }
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000083 BeginInstallFunction::SetIgnoreUserGestureForTests(false);
84 ASSERT_TRUE(RunInstallTest("no_user_gesture.html"));
Kristian Monsenbda42a82010-10-27 13:27:14 +010085}