Revert "Extensions: Navigate to default chrome page on extension unload"

This reverts commit 4d546d6ecc0e621a0d08f804a9e25c4427055740.

Reason for revert: this patch caused a bug where we leave extraneous
windows around when coming out of sleep.

TBR=rdevlin.cronin@chromium.org, sky@chromium.org (c/b/ui/browser - clean revert)

(cherry picked from commit f16ef54406c24f856c79546dcef4937ce580b696)

Bug: 818351
Change-Id: I3cf6d60a4588b36619dc4e461c3b8cf29722d6cd
Reviewed-on: https://chromium-review.googlesource.com/947473
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: Ɓukasz Anforowicz <lukasza@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#540720}
Reviewed-on: https://chromium-review.googlesource.com/949306
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#658}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/chrome/browser/extensions/extension_web_ui_browsertest.cc b/chrome/browser/extensions/extension_web_ui_browsertest.cc
deleted file mode 100644
index 169bfe2c..0000000
--- a/chrome/browser/extensions/extension_web_ui_browsertest.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/extension_browsertest.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/test/browser_test_utils.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/test_extension_registry_observer.h"
-#include "extensions/common/extension.h"
-#include "net/test/embedded_test_server/embedded_test_server.h"
-
-using ExtensionWebUIBrowserTest = ExtensionBrowserTest;
-
-namespace extensions {
-
-IN_PROC_BROWSER_TEST_F(ExtensionWebUIBrowserTest,
-                       NavigateToDefaultChromePageOnExtensionUnload) {
-  TabStripModel* tab_strip_model = browser()->tab_strip_model();
-
-  const Extension* extension =
-      LoadExtension(test_data_dir_.AppendASCII("api_test")
-                        .AppendASCII("override")
-                        .AppendASCII("history"));
-  ASSERT_TRUE(extension);
-  std::string extension_id = extension->id();
-
-  // Open the chrome://history/ page in the current tab.
-  GURL extension_url(chrome::kChromeUIHistoryURL);
-  ui_test_utils::NavigateToURL(browser(), extension_url);
-  content::WaitForLoadStop(tab_strip_model->GetActiveWebContents());
-
-  // Check that the chrome://history/ page contains the extension's content.
-  std::string location;
-  EXPECT_TRUE(content::ExecuteScriptAndExtractString(
-      browser()->tab_strip_model()->GetActiveWebContents(),
-      "domAutomationController.send(location.href);\n", &location));
-  EXPECT_EQ(extension_id, GURL(location).host());  // Extension has control.
-
-  ASSERT_EQ(1, tab_strip_model->count());
-
-  // Uninstall the extension.
-  ExtensionService* service =
-      ExtensionSystem::Get(browser()->profile())->extension_service();
-  ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile());
-  TestExtensionRegistryObserver registry_observer(registry);
-  service->UnloadExtension(extension->id(), UnloadedExtensionReason::UNINSTALL);
-  registry_observer.WaitForExtensionUnloaded();
-
-  // Check that the opened chrome://history/ page contains the default chrome
-  // history page content.
-  ASSERT_EQ(1, tab_strip_model->count());
-  content::WaitForLoadStop(tab_strip_model->GetActiveWebContents());
-  EXPECT_EQ(
-      chrome::kChromeUIHistoryURL,
-      tab_strip_model->GetActiveWebContents()->GetLastCommittedURL().spec());
-
-  EXPECT_TRUE(content::ExecuteScriptAndExtractString(
-      tab_strip_model->GetActiveWebContents(),
-      "domAutomationController.send(location.href);\n", &location));
-  // Default history page has control.
-  EXPECT_EQ(chrome::kChromeUIHistoryURL, GURL(location).spec());
-}
-
-}  // namespace extensions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 1067eec..b8db847 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -2103,21 +2103,7 @@
            web_contents->GetURL().host_piece() == extension->id()) ||
           (extensions::TabHelper::FromWebContents(web_contents)
                ->extension_app() == extension)) {
-        if (tab_strip_model_->count() > 1) {
-          tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
-        } else {
-          // If there is only 1 tab remaining, do not close it and instead
-          // navigate to the default NTP. Note that if there is an installed
-          // extension that overrides the NTP page, that extension's content
-          // will override the NTP contents.
-          GURL url(chrome::kChromeUINewTabURL);
-          web_contents->GetController().LoadURL(
-              url,
-              content::Referrer::SanitizeForRequest(
-                  url,
-                  content::Referrer(url, blink::kWebReferrerPolicyDefault)),
-              ui::PAGE_TRANSITION_RELOAD, std::string());
-        }
+        tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
       } else {
         chrome::UnmuteIfMutedByExtension(web_contents, extension->id());
       }
diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc
index 07ce8a5..493ccbc 100644
--- a/chrome/browser/ui/browser_browsertest.cc
+++ b/chrome/browser/ui/browser_browsertest.cc
@@ -34,7 +34,6 @@
 #include "chrome/browser/devtools/devtools_window_testing.h"
 #include "chrome/browser/extensions/extension_browsertest.h"
 #include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_tab_util.h"
 #include "chrome/browser/extensions/extension_util.h"
 #include "chrome/browser/extensions/tab_helper.h"
 #include "chrome/browser/first_run/first_run.h"
@@ -107,7 +106,6 @@
 #include "content/public/test/test_navigation_observer.h"
 #include "extensions/browser/extension_registry.h"
 #include "extensions/browser/extension_system.h"
-#include "extensions/browser/test_extension_registry_observer.h"
 #include "extensions/browser/uninstall_reason.h"
 #include "extensions/common/constants.h"
 #include "extensions/common/extension.h"
@@ -1120,45 +1118,6 @@
   ASSERT_EQ(1, browser()->tab_strip_model()->count());
 }
 
-// Tests that when an extension is unloaded, if only one tab is opened
-// containing extenions-related content, then the tab is kept open and is
-// directed to the default NTP.
-IN_PROC_BROWSER_TEST_F(BrowserTest, NavigateToDefaultNTPPageOnExtensionUnload) {
-  ASSERT_TRUE(embedded_test_server()->Start());
-  TabStripModel* tab_strip_model = browser()->tab_strip_model();
-
-  const Extension* extension =
-      LoadExtension(test_data_dir_.AppendASCII("options_page/"));
-  ASSERT_TRUE(extension);
-
-  GURL extension_url = extension->GetResourceURL("options.html");
-  ui_test_utils::NavigateToURL(browser(), extension_url);
-  content::WaitForLoadStop(tab_strip_model->GetActiveWebContents());
-
-  ASSERT_EQ(1, browser()->tab_strip_model()->count());
-  EXPECT_EQ(
-      extension_url.spec(),
-      tab_strip_model->GetActiveWebContents()->GetLastCommittedURL().spec());
-
-  // Uninstall the extension.
-  ExtensionService* service =
-      extensions::ExtensionSystem::Get(browser()->profile())
-          ->extension_service();
-  extensions::ExtensionRegistry* registry =
-      extensions::ExtensionRegistry::Get(browser()->profile());
-  extensions::TestExtensionRegistryObserver registry_observer(registry);
-  service->UnloadExtension(extension->id(),
-                           extensions::UnloadedExtensionReason::UNINSTALL);
-  registry_observer.WaitForExtensionUnloaded();
-  content::WaitForLoadStop(tab_strip_model->GetActiveWebContents());
-
-  // There should only be one tab now, with the NTP loaded.
-  ASSERT_EQ(1, tab_strip_model->count());
-  EXPECT_EQ(
-      chrome::kChromeUINewTabURL,
-      tab_strip_model->GetActiveWebContents()->GetLastCommittedURL().spec());
-}
-
 // Open with --app-id=<id>, and see that an application tab opens by default.
 IN_PROC_BROWSER_TEST_F(BrowserTest, AppIdSwitch) {
   ASSERT_TRUE(embedded_test_server()->Start());
@@ -2413,7 +2372,7 @@
       web_contents->GetContainerBounds().size();
   RenderViewSizeObserver observer(web_contents, browser()->window());
 
-  // Navigate to a non-NTP, without resizing WebContentsView.
+  // Navigate to a non-NTP page, without resizing WebContentsView.
   ui_test_utils::NavigateToURL(browser(),
                                embedded_test_server()->GetURL("/title1.html"));
   ASSERT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
@@ -2451,7 +2410,7 @@
   EXPECT_EQ(wcv_commit_size0, web_contents->GetContainerBounds().size());
 #endif
 
-  // Navigate to another non-NTP, without resizing WebContentsView.
+  // Navigate to another non-NTP page, without resizing WebContentsView.
   ui_test_utils::NavigateToURL(browser(),
                                https_test_server.GetURL("/title2.html"));
   ASSERT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
@@ -2467,7 +2426,7 @@
             web_contents->GetRenderWidgetHostView()->GetViewBounds().size());
   EXPECT_EQ(wcv_commit_size1, web_contents->GetContainerBounds().size());
 
-  // Navigate from NTP to a non-NTP, resizing WebContentsView while
+  // Navigate from NTP to a non-NTP page, resizing WebContentsView while
   // navigation entry is pending.
   ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
   gfx::Size wcv_resize_insets(1, 1);
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index 4eef3ce..540a6b0 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -1256,7 +1256,6 @@
         "../browser/extensions/extension_unload_browsertest.cc",
         "../browser/extensions/extension_url_rewrite_browsertest.cc",
         "../browser/extensions/extension_view_host_factory_browsertest.cc",
-        "../browser/extensions/extension_web_ui_browsertest.cc",
         "../browser/extensions/extension_websocket_apitest.cc",
         "../browser/extensions/extension_webui_apitest.cc",
         "../browser/extensions/extension_with_management_policy_apitest.cc",