Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 6 #include "chrome/common/extensions/manifest_url_handler.h" | |
| 7 #include "extensions/common/manifest_constants.h" | 6 #include "extensions/common/manifest_constants.h" |
| 7 #include "extensions/common/manifest_handlers/options_page_info.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace errors = extensions::manifest_errors; | 10 namespace errors = extensions::manifest_errors; |
| 11 | 11 |
| 12 class OptionsPageManifestTest : public ExtensionManifestTest { | 12 class OptionsPageManifestTest : public ExtensionManifestTest { |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { | 15 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { |
| 16 scoped_refptr<extensions::Extension> extension; | 16 scoped_refptr<extensions::Extension> extension; |
| 17 | |
| 18 // Allow options page with absolute URL in hosted apps. | 17 // Allow options page with absolute URL in hosted apps. |
| 19 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); | 18 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); |
| 20 EXPECT_STREQ("http", | 19 EXPECT_STREQ("http", |
| 21 extensions::ManifestURL::GetOptionsPage(extension.get()) | 20 extensions::OptionsPageInfo::GetOptionsPage(extension.get()) |
| 22 .scheme().c_str()); | 21 .scheme() |
| 23 EXPECT_STREQ( | 22 .c_str()); |
| 24 "example.com", | 23 EXPECT_STREQ("example.com", |
| 25 extensions::ManifestURL::GetOptionsPage(extension.get()).host().c_str()); | 24 extensions::OptionsPageInfo::GetOptionsPage(extension.get()) |
| 25 .host() | |
| 26 .c_str()); | |
| 26 EXPECT_STREQ("options.html", | 27 EXPECT_STREQ("options.html", |
| 27 extensions::ManifestURL::GetOptionsPage(extension.get()) | 28 extensions::OptionsPageInfo::GetOptionsPage(extension.get()) |
| 28 .ExtractFileName().c_str()); | 29 .ExtractFileName() |
| 30 .c_str()); | |
| 29 | 31 |
| 30 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); | 32 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); |
| 31 EXPECT_TRUE(extensions::ManifestURL::GetOptionsPage(extension.get()) | 33 EXPECT_TRUE( |
| 32 .is_empty()); | 34 extensions::OptionsPageInfo::GetOptionsPage(extension.get()).is_empty()); |
| 33 | 35 |
| 34 Testcase testcases[] = { | 36 Testcase testcases[] = { |
| 35 // Forbid options page with relative URL in hosted apps. | 37 // Forbid options page with relative URL in hosted apps. |
| 36 Testcase("hosted_app_relative_options.json", | 38 Testcase("hosted_app_relative_options.json", |
| 37 errors::kInvalidOptionsPageInHostedApp), | 39 errors::kInvalidOptionsPageInHostedApp), |
| 38 | 40 |
| 39 // Forbid options page with non-(http|https) scheme in hosted app. | 41 // Forbid options page with non-(http|https) scheme in hosted app. |
| 40 Testcase("hosted_app_file_options.json", | 42 Testcase("hosted_app_file_options.json", |
| 41 errors::kInvalidOptionsPageInHostedApp), | 43 errors::kInvalidOptionsPageInHostedApp), |
| 42 | 44 |
| 43 // Forbid absolute URL for options page in packaged apps. | 45 // Forbid absolute URL for options page in packaged apps. |
| 44 Testcase("packaged_app_absolute_options.json", | 46 Testcase("packaged_app_absolute_options.json", |
| 45 errors::kInvalidOptionsPageExpectUrlInPackage) | 47 errors::kInvalidOptionsPageExpectUrlInPackage) |
| 46 }; | 48 }; |
| 47 RunTestcases(testcases, arraysize(testcases), | 49 RunTestcases(testcases, arraysize(testcases), |
| 48 EXPECT_TYPE_ERROR); | 50 EXPECT_TYPE_ERROR); |
| 49 } | 51 } |
| 52 | |
| 53 // Tests for the options_ui.page manifest field | |
| 54 TEST_F(OptionsPageManifestTest, OptionsUIPage) { | |
| 55 scoped_refptr<extensions::Extension> extension; | |
| 56 | |
| 57 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
| 58 EXPECT_EQ( | |
| 59 "chrome-extension", | |
| 60 extensions::OptionsPageInfo::GetOptionsPage(extension.get()).scheme()); | |
| 61 EXPECT_EQ( | |
| 62 "/options.html", | |
| 63 extensions::OptionsPageInfo::GetOptionsPage(extension.get()).path()); | |
|
not at google - send to devlin
2014/08/29 05:39:23
Odd to be comparing the parts separately. Can you
ericzeng
2014/08/29 16:52:22
I'll need the extension id, but yes that should wo
ericzeng
2014/08/29 22:08:50
Done.
| |
| 64 | |
| 65 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); | |
| 66 EXPECT_EQ( | |
| 67 "chrome-extension", | |
| 68 extensions::OptionsPageInfo::GetOptionsPage(extension.get()).scheme()); | |
| 69 EXPECT_EQ( | |
| 70 "/newoptions.html", | |
| 71 extensions::OptionsPageInfo::GetOptionsPage(extension.get()).path()); | |
| 72 | |
| 73 Testcase testcases[] = { | |
| 74 Testcase("options_ui_page_bad_url.json", errors::kInvalidOptionsUIPage)}; | |
| 75 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); | |
| 76 } | |
| 77 | |
| 78 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields | |
| 79 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { | |
| 80 scoped_refptr<extensions::Extension> extension; | |
| 81 | |
| 82 extension = LoadAndExpectSuccess("options_ui_flags_true.json"); | |
| 83 EXPECT_TRUE(extensions::OptionsPageInfo::ChromeStyle(extension.get())); | |
| 84 EXPECT_TRUE(extensions::OptionsPageInfo::OpenInTab(extension.get())); | |
| 85 | |
| 86 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); | |
| 87 EXPECT_FALSE(extensions::OptionsPageInfo::ChromeStyle(extension.get())); | |
| 88 EXPECT_FALSE(extensions::OptionsPageInfo::OpenInTab(extension.get())); | |
| 89 | |
| 90 // If chrome_style and open_in_tab are not set, they should be false | |
| 91 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
| 92 EXPECT_FALSE(extensions::OptionsPageInfo::ChromeStyle(extension.get())); | |
| 93 EXPECT_FALSE(extensions::OptionsPageInfo::OpenInTab(extension.get())); | |
| 94 } | |
|
not at google - send to devlin
2014/08/29 05:39:23
Could you add tests with the feature switch turned
ericzeng
2014/08/29 16:52:22
The feature switch doesn't affect any of the manif
ericzeng
2014/08/29 22:08:50
Done.
| |
| OLD | NEW |