blob: 02154d3d352f1cad8b8c0c7fc80a61c076e86700 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2018 The Chromium Authors
David Bertoni79661572018-08-28 23:51:142// 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 Bertoni79661572018-08-28 23:51:1411#include "chrome/common/chrome_paths.h"
Matt Siembor39462b32019-05-07 20:20:4412#include "chrome/common/webui_url_constants.h"
David Bertoni79661572018-08-28 23:51:1413#include "content/public/browser/web_contents.h"
Peter Kasting919ce652020-05-07 10:22:3614#include "content/public/test/browser_test.h"
David Bertoni79661572018-08-28 23:51:1415#include "content/public/test/browser_test_utils.h"
16#include "url/gurl.h"
17
18using ExtensionsInternalsTest = extensions::ExtensionBrowserTest;
19
20IN_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 Cook414964c62025-04-24 18:34:5126 extensions::ChromeTestExtensionLoader loader(profile());
David Bertoni79661572018-08-28 23:51:1427 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 Siembor39462b32019-05-07 20:20:4432 GURL navigation_url(
33 content::GetWebUIURL(chrome::kChromeUIExtensionsInternalsHost));
James Cook414964c62025-04-24 18:34:5134 ASSERT_TRUE(NavigateToURL(navigation_url));
35 content::WebContents* web_contents = GetActiveWebContents();
David Bertoni79661572018-08-28 23:51:1436 ASSERT_TRUE(web_contents);
37 EXPECT_EQ(navigation_url, web_contents->GetLastCommittedURL());
38 EXPECT_FALSE(web_contents->IsCrashed());
David Bertoni79661572018-08-28 23:51:1439
40 // Look for a bit of JSON that has the extension's unique ID.
Chris Fredricksonfdcb8042023-04-25 18:39:5441 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 Bertoni79661572018-08-28 23:51:1447}