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

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

Issue 2986043002: The Appcache subresource URL factory needs to inform the URLLoaderClient if there is a failure. (Closed)
Patch Set: Change request count check to be greater than 1. 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 "build/build_config.h"
10 #include "content/browser/appcache/appcache_subresource_url_factory.h"
11 #include "content/public/common/content_features.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h"
17 #include "content/public/test/test_utils.h"
18 #include "content/shell/browser/shell.h"
19 #include "net/dns/mock_host_resolver.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "net/test/embedded_test_server/http_request.h"
22 #include "net/test/embedded_test_server/http_response.h"
23 namespace content {
24
25 // This class currently enables the network service feature, which allows us to
26 // test the AppCache code in that mode.
27 class AppCacheNetworkServiceBrowserTest : public ContentBrowserTest {
28 public:
29 AppCacheNetworkServiceBrowserTest() {}
30
31 // Handler to count the number of requests.
32 std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
33 const net::test_server::HttpRequest& request) {
34 request_count_++;
35 return std::unique_ptr<net::test_server::HttpResponse>();
36 }
37
38 // Call this to reset the request_count_.
39 void Clear() { request_count_ = 0; }
40
41 int request_count() const { return request_count_; }
42
43 protected:
44 void SetUpCommandLine(base::CommandLine* command_line) override {
45 command_line->AppendSwitchASCII(switches::kEnableFeatures,
46 features::kNetworkService.name);
47 }
48
49 private:
50 // Tracks the number of requests.
51 int request_count_ = 0;
52
53 DISALLOW_COPY_AND_ASSIGN(AppCacheNetworkServiceBrowserTest);
54 };
55
56 // The network service process launch DCHECK's on Android. The bug
57 // here http://crbug.com/748764. It looks like unsandboxed utility
58 // processes are not supported on Android.
59 #if !defined(OS_ANDROID)
60 // This test validates that navigating to a TLD which has an AppCache
61 // associated with it and then navigating to another TLD within that
62 // host clears the previously registered factory. We verify this by
63 // validating that request count for the last navigation.
64 IN_PROC_BROWSER_TEST_F(AppCacheNetworkServiceBrowserTest,
65 VerifySubresourceFactoryClearedOnNewNavigation) {
66 std::unique_ptr<net::EmbeddedTestServer> embedded_test_server(
67 new net::EmbeddedTestServer());
68
69 embedded_test_server->RegisterRequestHandler(
70 base::Bind(&AppCacheNetworkServiceBrowserTest::HandleRequest,
71 base::Unretained(this)));
72
73 base::FilePath content_test_data(FILE_PATH_LITERAL("content/test/data"));
74 embedded_test_server->AddDefaultHandlers(content_test_data);
75
76 ASSERT_TRUE(embedded_test_server->Start());
77
78 GURL main_url =
79 embedded_test_server->GetURL("/appcache/simple_page_with_manifest.html");
80
81 base::string16 expected_title = base::ASCIIToUTF16("AppCache updated");
82 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
83
84 // Load the main page twice. The second navigation should have AppCache
85 // initialized for the page.
86 EXPECT_TRUE(NavigateToURL(shell(), main_url));
87 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
88
89 TestNavigationObserver observer(shell()->web_contents());
90 EXPECT_TRUE(NavigateToURL(shell(), main_url));
91 EXPECT_EQ(main_url, observer.last_navigation_url());
92 EXPECT_TRUE(observer.last_navigation_succeeded());
93
94 Clear();
95 GURL page_no_manifest =
96 embedded_test_server->GetURL("/appcache/simple_page_no_manifest.html");
97
98 EXPECT_TRUE(NavigateToURL(shell(), page_no_manifest));
99 // We expect two requests for simple_page_no_manifest.html. The request
100 // for the main page and the logo.
101 EXPECT_GT(request_count(), 1);
102 EXPECT_EQ(page_no_manifest, observer.last_navigation_url());
103 EXPECT_TRUE(observer.last_navigation_succeeded());
104 }
105 #endif
106
107 } // 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