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

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 2149323003: Change the way that gzipped resources are loaded from resources.pak (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: whoops Created 4 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 | « content/public/browser/web_ui_data_source.h ('k') | net/filter/gzip_header.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <tuple> 8 #include <tuple>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "content/public/browser/render_frame_host.h" 51 #include "content/public/browser/render_frame_host.h"
52 #include "content/public/browser/render_process_host.h" 52 #include "content/public/browser/render_process_host.h"
53 #include "content/public/browser/render_view_host.h" 53 #include "content/public/browser/render_view_host.h"
54 #include "content/public/browser/storage_partition.h" 54 #include "content/public/browser/storage_partition.h"
55 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
56 #include "content/public/test/test_navigation_observer.h" 56 #include "content/public/test/test_navigation_observer.h"
57 #include "content/public/test/test_utils.h" 57 #include "content/public/test/test_utils.h"
58 #include "content/test/accessibility_browser_test_utils.h" 58 #include "content/test/accessibility_browser_test_utils.h"
59 #include "net/base/filename_util.h" 59 #include "net/base/filename_util.h"
60 #include "net/cookies/cookie_store.h" 60 #include "net/cookies/cookie_store.h"
61 #include "net/filter/filter.h"
62 #include "net/filter/gzip_header.h"
61 #include "net/test/embedded_test_server/embedded_test_server.h" 63 #include "net/test/embedded_test_server/embedded_test_server.h"
62 #include "net/test/embedded_test_server/http_request.h" 64 #include "net/test/embedded_test_server/http_request.h"
63 #include "net/test/embedded_test_server/http_response.h" 65 #include "net/test/embedded_test_server/http_response.h"
64 #include "net/test/python_utils.h" 66 #include "net/test/python_utils.h"
65 #include "net/url_request/url_request_context.h" 67 #include "net/url_request/url_request_context.h"
66 #include "net/url_request/url_request_context_getter.h" 68 #include "net/url_request/url_request_context_getter.h"
67 #include "testing/gtest/include/gtest/gtest.h" 69 #include "testing/gtest/include/gtest/gtest.h"
68 #include "ui/base/clipboard/clipboard.h" 70 #include "ui/base/clipboard/clipboard.h"
69 #include "ui/base/clipboard/scoped_clipboard_writer.h" 71 #include "ui/base/clipboard/scoped_clipboard_writer.h"
70 #include "ui/base/resource/resource_bundle.h" 72 #include "ui/base/resource/resource_bundle.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // NavigationThrottle: 370 // NavigationThrottle:
369 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { 371 NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
370 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 372 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
371 on_will_start_request_closure_); 373 on_will_start_request_closure_);
372 return NavigationThrottle::DEFER; 374 return NavigationThrottle::DEFER;
373 } 375 }
374 376
375 base::Closure on_will_start_request_closure_; 377 base::Closure on_will_start_request_closure_;
376 }; 378 };
377 379
380 bool HasGzipHeader(const base::RefCountedMemory& maybe_gzipped) {
381 net::GZipHeader header;
382 net::GZipHeader::Status header_status = net::GZipHeader::INCOMPLETE_HEADER;
383 // TODO(dbeam): why do we even have this lever^Wparameter?
mmenke 2016/08/18 14:40:35 ^W? I assume it's so ReadMore can continue where
Dan Beam 2016/08/18 20:56:50 means "remove word" https://en.wikipedia.org/wiki/
384 const char* header_end = NULL;
mmenke 2016/08/18 14:40:36 nullptr
Dan Beam 2016/08/18 20:56:50 Done.
385 while (header_status == net::GZipHeader::INCOMPLETE_HEADER) {
386 header_status = header.ReadMore(maybe_gzipped.front_as<char>(),
387 maybe_gzipped.size(),
388 &header_end);
389 }
390 return header_status == net::GZipHeader::COMPLETE_HEADER;
391 }
392
393 void AppendGzippedResource(const base::RefCountedMemory& encoded,
394 std::string* to_append) {
395 std::unique_ptr<net::Filter> filter = net::Filter::GZipFactory();
mmenke 2016/08/18 14:40:36 Need to make net::Filter NET_EXPORT (It's NET_EXPO
Dan Beam 2016/08/18 20:56:50 Done.
396 memcpy(filter->stream_buffer()->data(), encoded.front_as<char>(),
397 encoded.size());
398 filter->FlushStreamBuffer(encoded.size());
399
400 const int kBufferSize = 4096;
401 char dest_buffer[kBufferSize];
402
403 net::Filter::FilterStatus status;
404 do {
405 int read_size = kBufferSize;
406 status = filter->ReadData(dest_buffer, &read_size);
407 ASSERT_NE(status, net::Filter::FILTER_ERROR);
408 to_append->append(dest_buffer, read_size);
409 } while (status != net::Filter::FILTER_DONE);
410 }
411
378 } // namespace 412 } // namespace
379 413
380 bool NavigateIframeToURL(WebContents* web_contents, 414 bool NavigateIframeToURL(WebContents* web_contents,
381 std::string iframe_id, 415 std::string iframe_id,
382 const GURL& url) { 416 const GURL& url) {
383 std::string script = base::StringPrintf( 417 std::string script = base::StringPrintf(
384 "setTimeout(\"" 418 "setTimeout(\""
385 "var iframes = document.getElementById('%s');iframes.src='%s';" 419 "var iframes = document.getElementById('%s');iframes.src='%s';"
386 "\",0)", 420 "\",0)",
387 iframe_id.c_str(), url.spec().c_str()); 421 iframe_id.c_str(), url.spec().c_str());
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 // Inject WebUI test runner script first prior to other scripts required to 871 // Inject WebUI test runner script first prior to other scripts required to
838 // run the test as scripts may depend on it being declared. 872 // run the test as scripts may depend on it being declared.
839 std::vector<int> ids; 873 std::vector<int> ids;
840 ids.push_back(IDR_WEBUI_JS_WEBUI_RESOURCE_TEST); 874 ids.push_back(IDR_WEBUI_JS_WEBUI_RESOURCE_TEST);
841 ids.insert(ids.end(), js_resource_ids.begin(), js_resource_ids.end()); 875 ids.insert(ids.end(), js_resource_ids.begin(), js_resource_ids.end());
842 876
843 std::string script; 877 std::string script;
844 for (std::vector<int>::iterator iter = ids.begin(); 878 for (std::vector<int>::iterator iter = ids.begin();
845 iter != ids.end(); 879 iter != ids.end();
846 ++iter) { 880 ++iter) {
847 scoped_refptr<base::RefCountedMemory> resource = 881 scoped_refptr<base::RefCountedMemory> bytes =
848 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(*iter); 882 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(*iter);
849 script.append(resource->front_as<char>(), resource->size()); 883
884 if (HasGzipHeader(*bytes))
885 AppendGzippedResource(*bytes, &script);
886 else
887 script.append(bytes->front_as<char>(), bytes->size());
888
850 script.append("\n"); 889 script.append("\n");
851 } 890 }
852 if (!ExecuteScript(web_contents, script)) 891 if (!ExecuteScript(web_contents, script))
853 return false; 892 return false;
854 893
855 DOMMessageQueue message_queue; 894 DOMMessageQueue message_queue;
856 if (!ExecuteScript(web_contents, "runTests()")) 895 if (!ExecuteScript(web_contents, "runTests()"))
857 return false; 896 return false;
858 897
859 std::string message; 898 std::string message;
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 1690
1652 bool TestNavigationManager::ShouldMonitorNavigation(NavigationHandle* handle) { 1691 bool TestNavigationManager::ShouldMonitorNavigation(NavigationHandle* handle) {
1653 if (handle_ || handle->GetURL() != url_) 1692 if (handle_ || handle->GetURL() != url_)
1654 return false; 1693 return false;
1655 if (handled_navigation_) 1694 if (handled_navigation_)
1656 return false; 1695 return false;
1657 return true; 1696 return true;
1658 } 1697 }
1659 1698
1660 } // namespace content 1699 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/web_ui_data_source.h ('k') | net/filter/gzip_header.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698