Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: content/browser/appcache/appcache_browsertest.cc

Issue 2991443002: The Appcache subresource URL factory needs to inform the URLLoaderClient if there is a failure. (Closed)
Patch Set: Provide a way to turn off certain errors like missing host etc in the factory for tests. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 <stdint.h>
6
7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/appcache/appcache_subresource_url_factory.h"
10 #include "content/public/common/content_features.h"
11 #include "content/public/common/content_switches.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/public/test/test_navigation_observer.h"
16 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h"
18 #include "net/dns/mock_host_resolver.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h"
20
21 namespace content {
22
23 // This class currently enables the network service feature, which allows us to
24 // test the AppCache code in that mode.
25 class AppCacheNetworkServiceBrowserTest : public ContentBrowserTest {
26 public:
27 AppCacheNetworkServiceBrowserTest() {}
28
29 protected:
30 void SetUpCommandLine(base::CommandLine* command_line) override {
31 command_line->AppendSwitchASCII(switches::kEnableFeatures,
32 features::kNetworkService.name);
33 }
34
35 void SetUpOnMainThread() override {
36 ASSERT_TRUE(embedded_test_server()->Start());
37 }
38
39 void ValidateSubresourceFactoryClearedOnNewNavigation(
40 bool turn_off_factory_errors) {
41 if (turn_off_factory_errors)
42 AppCacheSubresourceURLFactory::SetForTesting(true);
43
44 GURL main_url = embedded_test_server()->GetURL(
45 "/appcache/simple_page_with_manifest.html");
46
47 base::string16 expected_title = base::ASCIIToUTF16("AppCache updated");
48 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
49
50 // Load the main page twice. The second navigation should have AppCache
51 // initialized for the page.
52 EXPECT_TRUE(NavigateToURL(shell(), main_url));
53 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
54
55 TestNavigationObserver observer(shell()->web_contents());
56 EXPECT_TRUE(NavigateToURL(shell(), main_url));
57 EXPECT_EQ(main_url, observer.last_navigation_url());
58 EXPECT_TRUE(observer.last_navigation_succeeded());
59
60 GURL page_no_manifest = embedded_test_server()->GetURL(
61 "/appcache/simple_page_no_manifest.html");
62
63 EXPECT_TRUE(NavigateToURL(shell(), page_no_manifest));
64 EXPECT_EQ(page_no_manifest, observer.last_navigation_url());
65 EXPECT_TRUE(observer.last_navigation_succeeded());
66
67 if (turn_off_factory_errors)
68 AppCacheSubresourceURLFactory::SetForTesting(false);
69 }
70 };
71
72 // This test validates that navigating to a TLD which has an AppCache
73 // associated with it and then navigating to another TLD within that
74 // host does not hang. The AppCache subresource factory returns errors
75 // if the host is invalid. This test leaves that behavior on.
76 IN_PROC_BROWSER_TEST_F(
77 AppCacheNetworkServiceBrowserTest,
78 VerifySubresourceFactoryClearedOnNewNavigationWithFactoryErrorOn) {
79 ValidateSubresourceFactoryClearedOnNewNavigation(false);
80 }
81
82 // Same test as above with the difference being we turn off the AppCache
83 // subresource factory errors on a missing host. This validates that
84 // RenderFrameImpl cleares the factory correctly on a new navigation.
85 IN_PROC_BROWSER_TEST_F(
86 AppCacheNetworkServiceBrowserTest,
87 VerifySubresourceFactoryClearedOnNewNavigationWithFactoryErrorOff) {
88 ValidateSubresourceFactoryClearedOnNewNavigation(true);
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698