OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/extension_install_ui.h" | 7 #include "chrome/browser/extensions/extension_install_ui.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_webstore_private_api.h" | 9 #include "chrome/browser/extensions/extension_webstore_private_api.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 // Replace the host with 'www.example.com' so it matches the web store | 45 // Replace the host with 'www.example.com' so it matches the web store |
46 // app's extent. | 46 // app's extent. |
47 GURL::Replacements replace_host; | 47 GURL::Replacements replace_host; |
48 std::string host_str("www.example.com"); | 48 std::string host_str("www.example.com"); |
49 replace_host.SetHostStr(host_str); | 49 replace_host.SetHostStr(host_str); |
50 | 50 |
51 return url.ReplaceComponents(replace_host); | 51 return url.ReplaceComponents(replace_host); |
52 } | 52 } |
53 | 53 |
54 // Navigates to |page| and runs the Extension API test there. | 54 // Navigates to |page| and runs the Extension API test there. Any downloads |
55 bool RunInstallTest(const std::string& page) { | 55 // of extensions will return the contents of |crx_file|. |
56 GURL crx_url = GetTestServerURL("extension.crx"); | 56 bool RunInstallTest(const std::string& page, const std::string& crx_file) { |
| 57 GURL crx_url = GetTestServerURL(crx_file); |
57 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 58 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
58 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 59 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
59 | 60 |
60 GURL page_url = GetTestServerURL(page); | 61 GURL page_url = GetTestServerURL(page); |
61 return RunPageTest(page_url.spec()); | 62 return RunPageTest(page_url.spec()); |
62 } | 63 } |
63 | 64 |
64 ExtensionService* service() { | 65 ExtensionService* service() { |
65 return browser()->profile()->GetExtensionService(); | 66 return browser()->profile()->GetExtensionService(); |
66 } | 67 } |
67 }; | 68 }; |
68 | 69 |
69 // TODO(asargent) - flaky; see crbug.com/80606. | 70 // TODO(asargent) - flaky; see crbug.com/80606. |
70 // Test cases where the user accepts the install confirmation dialog. | 71 // Test cases where the user accepts the install confirmation dialog. |
71 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, FLAKY_InstallAccepted) { | 72 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, FLAKY_InstallAccepted) { |
72 ASSERT_TRUE(RunInstallTest("accepted.html")); | 73 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx")); |
| 74 } |
| 75 |
| 76 // Tests passing a localized name. |
| 77 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { |
| 78 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); |
73 } | 79 } |
74 | 80 |
75 // Now test the case where the user cancels the confirmation dialog. | 81 // Now test the case where the user cancels the confirmation dialog. |
76 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { | 82 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { |
77 BeginInstallWithManifestFunction::SetAutoConfirmForTests(false); | 83 BeginInstallWithManifestFunction::SetAutoConfirmForTests(false); |
78 ASSERT_TRUE(RunInstallTest("cancelled.html")); | 84 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); |
79 } | 85 } |
80 | 86 |
81 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallNoGesture) { | 87 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallNoGesture) { |
82 BeginInstallFunction::SetIgnoreUserGestureForTests(false); | 88 BeginInstallFunction::SetIgnoreUserGestureForTests(false); |
83 ASSERT_TRUE(RunInstallTest("no_user_gesture.html")); | 89 ASSERT_TRUE(RunInstallTest("no_user_gesture.html", "extension.crx")); |
84 } | 90 } |
85 | 91 |
86 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 92 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
87 IncorrectManifest1) { | 93 IncorrectManifest1) { |
88 ui_test_utils::WindowedNotificationObserver observer( | 94 ui_test_utils::WindowedNotificationObserver observer( |
89 NotificationType::EXTENSION_INSTALL_ERROR, | 95 NotificationType::EXTENSION_INSTALL_ERROR, |
90 NotificationService::AllSources()); | 96 NotificationService::AllSources()); |
91 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html")); | 97 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx")); |
92 observer.Wait(); | 98 observer.Wait(); |
93 } | 99 } |
94 | 100 |
95 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 101 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
96 IncorrectManifest2) { | 102 IncorrectManifest2) { |
97 ui_test_utils::WindowedNotificationObserver observer( | 103 ui_test_utils::WindowedNotificationObserver observer( |
98 NotificationType::EXTENSION_INSTALL_ERROR, | 104 NotificationType::EXTENSION_INSTALL_ERROR, |
99 NotificationService::AllSources()); | 105 NotificationService::AllSources()); |
100 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html")); | 106 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx")); |
101 observer.Wait(); | 107 observer.Wait(); |
102 } | 108 } |
OLD | NEW |