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

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: Disable the test for Android 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
« no previous file with comments | « no previous file | content/browser/appcache/appcache_subresource_url_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/test/embedded_test_server/http_request.h"
21 #include "net/test/embedded_test_server/http_response.h"
22 namespace content {
23
24 // This class currently enables the network service feature, which allows us to
25 // test the AppCache code in that mode.
26 class AppCacheNetworkServiceBrowserTest : public ContentBrowserTest {
27 public:
28 AppCacheNetworkServiceBrowserTest() {}
29
30 // Handler to count the number of requests.
31 std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
32 const net::test_server::HttpRequest& request) {
33 request_count_++;
34 return std::unique_ptr<net::test_server::HttpResponse>();
35 }
36
37 // Call this to reset the request_count_.
38 void Clear() { request_count_ = 0; }
39
40 int request_count() const { return request_count_; }
41
42 protected:
43 void SetUpCommandLine(base::CommandLine* command_line) override {
44 command_line->AppendSwitchASCII(switches::kEnableFeatures,
45 features::kNetworkService.name);
46 }
47
48 private:
49 // Tracks the number of requests.
50 int request_count_ = 0;
51 };
52
53 // The network service process launch DCHECK's on Android. The bug
54 // here http://crbug.com/748764. It looks like unsandboxed utility
55 // processes are not supported on Android.
56 #if !defined(OS_ANDROID)
57 // This test validates that navigating to a TLD which has an AppCache
58 // associated with it and then navigating to another TLD within that
59 // host clears the previously registered factory. We verify this by
60 // validating that request count for the last navigation.
61 IN_PROC_BROWSER_TEST_F(AppCacheNetworkServiceBrowserTest,
62 VerifySubresourceFactoryClearedOnNewNavigation) {
63 std::unique_ptr<net::EmbeddedTestServer> embedded_test_server(
64 new net::EmbeddedTestServer());
65
66 embedded_test_server->RegisterRequestHandler(
67 base::Bind(&AppCacheNetworkServiceBrowserTest::HandleRequest,
68 base::Unretained(this)));
69
70 base::FilePath content_test_data(FILE_PATH_LITERAL("content/test/data"));
71 embedded_test_server->AddDefaultHandlers(content_test_data);
72
73 ASSERT_TRUE(embedded_test_server->Start());
74
75 GURL main_url =
76 embedded_test_server->GetURL("/appcache/simple_page_with_manifest.html");
77
78 base::string16 expected_title = base::ASCIIToUTF16("AppCache updated");
79 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
80
81 // Load the main page twice. The second navigation should have AppCache
82 // initialized for the page.
83 EXPECT_TRUE(NavigateToURL(shell(), main_url));
84 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
85
86 TestNavigationObserver observer(shell()->web_contents());
87 EXPECT_TRUE(NavigateToURL(shell(), main_url));
88 EXPECT_EQ(main_url, observer.last_navigation_url());
89 EXPECT_TRUE(observer.last_navigation_succeeded());
90
91 Clear();
92 GURL page_no_manifest =
93 embedded_test_server->GetURL("/appcache/simple_page_no_manifest.html");
94
95 EXPECT_TRUE(NavigateToURL(shell(), page_no_manifest));
96 // We expect two requests for simple_page_no_manifest.html. The request
97 // for the main page and the logo.
98 EXPECT_EQ(request_count(), 2);
99 EXPECT_EQ(page_no_manifest, observer.last_navigation_url());
100 EXPECT_TRUE(observer.last_navigation_succeeded());
101 }
102 #endif
103
104 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/appcache/appcache_subresource_url_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698