Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [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/files/file_path.h" |
| 6 | #include "base/path_service.h" |
| 7 | #include "base/strings/stringprintf.h" |
| 8 | #include "chrome/browser/extensions/chrome_test_extension_loader.h" |
| 9 | #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 | #include "chrome/browser/profiles/profile.h" |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 11 | #include "chrome/common/chrome_paths.h" |
Matt Siembor | 39462b3 | 2019-05-07 20:20:44 | [diff] [blame] | 12 | #include "chrome/common/webui_url_constants.h" |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 13 | #include "content/public/browser/web_contents.h" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame] | 14 | #include "content/public/test/browser_test.h" |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 15 | #include "content/public/test/browser_test_utils.h" |
| 16 | #include "url/gurl.h" |
| 17 | |
| 18 | using ExtensionsInternalsTest = extensions::ExtensionBrowserTest; |
| 19 | |
| 20 | IN_PROC_BROWSER_TEST_F(ExtensionsInternalsTest, |
| 21 | TestExtensionsInternalsAreServed) { |
| 22 | // Install an extension that we can check for. |
| 23 | base::FilePath test_data_dir; |
| 24 | ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
| 25 | test_data_dir = test_data_dir.AppendASCII("extensions"); |
James Cook | 414964c6 | 2025-04-24 18:34:51 | [diff] [blame] | 26 | extensions::ChromeTestExtensionLoader loader(profile()); |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 27 | const extensions::Extension* extension = |
| 28 | loader.LoadExtension(test_data_dir.AppendASCII("good.crx")).get(); |
| 29 | ASSERT_TRUE(extension); |
| 30 | |
| 31 | // First, check that navigation succeeds. |
Matt Siembor | 39462b3 | 2019-05-07 20:20:44 | [diff] [blame] | 32 | GURL navigation_url( |
| 33 | content::GetWebUIURL(chrome::kChromeUIExtensionsInternalsHost)); |
James Cook | 414964c6 | 2025-04-24 18:34:51 | [diff] [blame] | 34 | ASSERT_TRUE(NavigateToURL(navigation_url)); |
| 35 | content::WebContents* web_contents = GetActiveWebContents(); |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 36 | ASSERT_TRUE(web_contents); |
| 37 | EXPECT_EQ(navigation_url, web_contents->GetLastCommittedURL()); |
| 38 | EXPECT_FALSE(web_contents->IsCrashed()); |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 39 | |
| 40 | // Look for a bit of JSON that has the extension's unique ID. |
Chris Fredrickson | fdcb804 | 2023-04-25 18:39:54 | [diff] [blame] | 41 | EXPECT_EQ(true, content::EvalJs( |
| 42 | web_contents, |
| 43 | base::StringPrintf("document.body.textContent && " |
| 44 | "document.body.textContent.indexOf(" |
| 45 | "'\"id\": \"%s\"') >= 0;", |
| 46 | extension->id().c_str()))); |
David Bertoni | 7966157 | 2018-08-28 23:51:14 | [diff] [blame] | 47 | } |