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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/test/histogram_tester.h" | |
| 7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 8 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 20 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
| 21 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 22 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
| 23 #include "extensions/browser/extension_util.h" | 24 #include "extensions/browser/extension_util.h" |
| 24 #include "extensions/browser/notification_types.h" | 25 #include "extensions/browser/notification_types.h" |
| 25 #include "extensions/browser/test_extension_registry_observer.h" | 26 #include "extensions/browser/test_extension_registry_observer.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | |
| 28 #include "testing/gtest/include/gtest/gtest.h" | |
| 26 | 29 |
| 27 namespace extensions { | 30 namespace extensions { |
| 28 | 31 |
| 29 class ExtensionFunctionalTest : public ExtensionBrowserTest { | 32 class ExtensionFunctionalTest : public ExtensionBrowserTest { |
| 30 public: | 33 public: |
| 31 void InstallExtensionSilently(ExtensionService* service, | 34 void InstallExtensionSilently(ExtensionService* service, |
| 32 const char* filename) { | 35 const char* filename) { |
| 33 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 36 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 34 size_t num_before = registry->enabled_extensions().size(); | 37 size_t num_before = registry->enabled_extensions().size(); |
| 35 | 38 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); | 110 EXPECT_TRUE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); |
| 108 | 111 |
| 109 // Disallow extension in incognito mode and verify. | 112 // Disallow extension in incognito mode and verify. |
| 110 service->EnableExtension(last_loaded_extension_id()); | 113 service->EnableExtension(last_loaded_extension_id()); |
| 111 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false); | 114 util::SetIsIncognitoEnabled(last_loaded_extension_id(), profile(), false); |
| 112 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); | 115 EXPECT_FALSE(util::IsIncognitoEnabled(last_loaded_extension_id(), profile())); |
| 113 } | 116 } |
| 114 | 117 |
| 115 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, | 118 IN_PROC_BROWSER_TEST_F(ExtensionFunctionalTest, |
| 116 FindingUnrelatedExtensionFramesFromAboutBlank) { | 119 FindingUnrelatedExtensionFramesFromAboutBlank) { |
| 120 base::HistogramTester histogram_tester; | |
| 121 | |
| 117 // Load an extension before adding tabs. | 122 // Load an extension before adding tabs. |
| 118 const extensions::Extension* extension = | 123 const extensions::Extension* extension = |
| 119 LoadExtension(test_data_dir_.AppendASCII("simple_with_file")); | 124 LoadExtension(test_data_dir_.AppendASCII("simple_with_file")); |
| 120 ASSERT_TRUE(extension); | 125 ASSERT_TRUE(extension); |
| 121 GURL extension_url = extension->GetResourceURL("file.html"); | 126 GURL extension_url = extension->GetResourceURL("file.html"); |
| 122 | 127 |
| 123 // Load the extension in two unrelated tabs. | 128 // Load the extension in two unrelated tabs. |
| 124 ui_test_utils::NavigateToURL(browser(), extension_url); | 129 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 125 ui_test_utils::NavigateToURLWithDisposition( | 130 ui_test_utils::NavigateToURLWithDisposition( |
| 126 browser(), extension_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, | 131 browser(), extension_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 | 164 |
| 160 // Verify that |tab1_popup| can find unrelated frames from the same extension | 165 // Verify that |tab1_popup| can find unrelated frames from the same extension |
| 161 // (i.e. that it can find |tab2|. | 166 // (i.e. that it can find |tab2|. |
| 162 std::string location_of_opened_window; | 167 std::string location_of_opened_window; |
| 163 EXPECT_TRUE(ExecuteScriptAndExtractString( | 168 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 164 tab1_popup, | 169 tab1_popup, |
| 165 "var w = window.open('', 'tab2');\n" | 170 "var w = window.open('', 'tab2');\n" |
| 166 "window.domAutomationController.send(w.location.href);", | 171 "window.domAutomationController.send(w.location.href);", |
| 167 &location_of_opened_window)); | 172 &location_of_opened_window)); |
| 168 EXPECT_EQ(tab2->GetLastCommittedURL(), location_of_opened_window); | 173 EXPECT_EQ(tab2->GetLastCommittedURL(), location_of_opened_window); |
| 174 | |
| 175 // Verify UMA got recorded as expected. | |
| 176 // DO NOT SUBMIT - need to flush/sync the histograms logged in the renderer | |
| 177 // for |tab1_popup|. | |
|
Łukasz Anforowicz
2017/06/07 23:24:35
How would a browser test force a sync in a canonic
| |
| 178 EXPECT_THAT(histogram_tester.GetAllSamples( | |
| 179 "Extensions.BrowsingInstanceViolation.ExtensionType"), | |
| 180 testing::ElementsAre(base::Bucket(Manifest::TYPE_EXTENSION, 1))); | |
| 181 EXPECT_THAT(histogram_tester.GetAllSamples( | |
| 182 "Extensions.BrowsingInstanceViolation.ExtensionViewType"), | |
| 183 testing::ElementsAre(base::Bucket(VIEW_TYPE_TAB_CONTENTS, 1))); | |
| 169 } | 184 } |
| 170 | 185 |
| 171 } // namespace extensions | 186 } // namespace extensions |
| OLD | NEW |