blob: 43bcec32608c0fb9b7f0a80af69206be4236dec8 [file] [log] [blame]
David Bertoni79661572018-08-28 23:51:141// Copyright 2018 The Chromium Authors. All rights reserved.
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"
11#include "chrome/browser/ui/browser.h"
12#include "chrome/browser/ui/tabs/tab_strip_model.h"
13#include "chrome/common/chrome_paths.h"
14#include "chrome/test/base/ui_test_utils.h"
15#include "content/public/browser/web_contents.h"
16#include "content/public/test/browser_test_utils.h"
17#include "url/gurl.h"
18
19using ExtensionsInternalsTest = extensions::ExtensionBrowserTest;
20
21IN_PROC_BROWSER_TEST_F(ExtensionsInternalsTest,
22 TestExtensionsInternalsAreServed) {
23 // Install an extension that we can check for.
24 base::FilePath test_data_dir;
25 ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
26 test_data_dir = test_data_dir.AppendASCII("extensions");
27 extensions::ChromeTestExtensionLoader loader(browser()->profile());
28 const extensions::Extension* extension =
29 loader.LoadExtension(test_data_dir.AppendASCII("good.crx")).get();
30 ASSERT_TRUE(extension);
31
32 // First, check that navigation succeeds.
33 GURL navigation_url("chrome://extensions-internals");
34 ui_test_utils::NavigateToURL(browser(), navigation_url);
35 content::WebContents* web_contents =
36 browser()->tab_strip_model()->GetActiveWebContents();
37 ASSERT_TRUE(web_contents);
38 EXPECT_EQ(navigation_url, web_contents->GetLastCommittedURL());
39 EXPECT_FALSE(web_contents->IsCrashed());
40 EXPECT_FALSE(web_contents->GetInterstitialPage());
41
42 // Look for a bit of JSON that has the extension's unique ID.
43 bool has_text = false;
44 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
45 web_contents,
46 base::StringPrintf("window.domAutomationController.send("
47 "document.body.textContent && "
48 "document.body.textContent.indexOf("
49 "'\"id\": \"%s\"') >= 0);",
50 extension->id().c_str()),
51 &has_text));
52 EXPECT_TRUE(has_text);
53}