| Index: content/browser/appcache/appcache_browsertest.cc
|
| diff --git a/content/browser/appcache/appcache_browsertest.cc b/content/browser/appcache/appcache_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..09b9736f2bdb74e40c5abfb5acbcf9b37bb81e2d
|
| --- /dev/null
|
| +++ b/content/browser/appcache/appcache_browsertest.cc
|
| @@ -0,0 +1,91 @@
|
| +// Copyright 2017 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 <stdint.h>
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "content/browser/appcache/appcache_subresource_url_factory.h"
|
| +#include "content/public/common/content_features.h"
|
| +#include "content/public/common/content_switches.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "content/public/test/content_browser_test.h"
|
| +#include "content/public/test/content_browser_test_utils.h"
|
| +#include "content/public/test/test_navigation_observer.h"
|
| +#include "content/public/test/test_utils.h"
|
| +#include "content/shell/browser/shell.h"
|
| +#include "net/dns/mock_host_resolver.h"
|
| +#include "net/test/embedded_test_server/embedded_test_server.h"
|
| +
|
| +namespace content {
|
| +
|
| +// This class currently enables the network service feature, which allows us to
|
| +// test the AppCache code in that mode.
|
| +class AppCacheNetworkServiceBrowserTest : public ContentBrowserTest {
|
| +public:
|
| + AppCacheNetworkServiceBrowserTest() {}
|
| +
|
| +protected:
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + command_line->AppendSwitchASCII(switches::kEnableFeatures,
|
| + features::kNetworkService.name);
|
| + }
|
| +
|
| + void SetUpOnMainThread() override {
|
| + ASSERT_TRUE(embedded_test_server()->Start());
|
| + }
|
| +
|
| + void ValidateSubresourceFactoryClearedOnNewNavigation(
|
| + bool turn_off_factory_errors) {
|
| + if (turn_off_factory_errors)
|
| + AppCacheSubresourceURLFactory::SetForTesting(true);
|
| +
|
| + GURL main_url = embedded_test_server()->GetURL(
|
| + "/appcache/simple_page_with_manifest.html");
|
| +
|
| + base::string16 expected_title = base::ASCIIToUTF16("AppCache updated");
|
| + TitleWatcher title_watcher(shell()->web_contents(), expected_title);
|
| +
|
| + // Load the main page twice. The second navigation should have AppCache
|
| + // initialized for the page.
|
| + EXPECT_TRUE(NavigateToURL(shell(), main_url));
|
| + EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
|
| +
|
| + TestNavigationObserver observer(shell()->web_contents());
|
| + EXPECT_TRUE(NavigateToURL(shell(), main_url));
|
| + EXPECT_EQ(main_url, observer.last_navigation_url());
|
| + EXPECT_TRUE(observer.last_navigation_succeeded());
|
| +
|
| + GURL page_no_manifest = embedded_test_server()->GetURL(
|
| + "/appcache/simple_page_no_manifest.html");
|
| +
|
| + EXPECT_TRUE(NavigateToURL(shell(), page_no_manifest));
|
| + EXPECT_EQ(page_no_manifest, observer.last_navigation_url());
|
| + EXPECT_TRUE(observer.last_navigation_succeeded());
|
| +
|
| + if (turn_off_factory_errors)
|
| + AppCacheSubresourceURLFactory::SetForTesting(false);
|
| + }
|
| +};
|
| +
|
| +// This test validates that navigating to a TLD which has an AppCache
|
| +// associated with it and then navigating to another TLD within that
|
| +// host does not hang. The AppCache subresource factory returns errors
|
| +// if the host is invalid. This test leaves that behavior on.
|
| +IN_PROC_BROWSER_TEST_F(
|
| + AppCacheNetworkServiceBrowserTest,
|
| + VerifySubresourceFactoryClearedOnNewNavigationWithFactoryErrorOn) {
|
| + ValidateSubresourceFactoryClearedOnNewNavigation(false);
|
| +}
|
| +
|
| +// Same test as above with the difference being we turn off the AppCache
|
| +// subresource factory errors on a missing host. This validates that
|
| +// RenderFrameImpl cleares the factory correctly on a new navigation.
|
| +IN_PROC_BROWSER_TEST_F(
|
| + AppCacheNetworkServiceBrowserTest,
|
| + VerifySubresourceFactoryClearedOnNewNavigationWithFactoryErrorOff) {
|
| + ValidateSubresourceFactoryClearedOnNewNavigation(true);
|
| +}
|
| +
|
| +} // namespace content
|
|
|