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

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: rename 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/filter.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 const char* header_end = nullptr;
384 while (header_status == net::GZipHeader::INCOMPLETE_HEADER) {
385 header_status = header.ReadMore(maybe_gzipped.front_as<char>(),
386 maybe_gzipped.size(),
387 &header_end);
388 }
389 return header_status == net::GZipHeader::COMPLETE_HEADER;
390 }
391
392 void AppendGzippedResource(const base::RefCountedMemory& encoded,
393 std::string* to_append) {
394 std::unique_ptr<net::Filter> filter = net::Filter::GZipFactory();
395 memcpy(filter->stream_buffer()->data(), encoded.front_as<char>(),
396 encoded.size());
397 filter->FlushStreamBuffer(encoded.size());
398
399 const int kBufferSize = 4096;
400 char dest_buffer[kBufferSize];
401
402 net::Filter::FilterStatus status;
403 do {
404 int read_size = kBufferSize;
405 status = filter->ReadData(dest_buffer, &read_size);
406 ASSERT_NE(status, net::Filter::FILTER_ERROR);
407 to_append->append(dest_buffer, read_size);
408 } while (status != net::Filter::FILTER_DONE);
409 }
410
378 } // namespace 411 } // namespace
379 412
380 bool NavigateIframeToURL(WebContents* web_contents, 413 bool NavigateIframeToURL(WebContents* web_contents,
381 std::string iframe_id, 414 std::string iframe_id,
382 const GURL& url) { 415 const GURL& url) {
383 std::string script = base::StringPrintf( 416 std::string script = base::StringPrintf(
384 "setTimeout(\"" 417 "setTimeout(\""
385 "var iframes = document.getElementById('%s');iframes.src='%s';" 418 "var iframes = document.getElementById('%s');iframes.src='%s';"
386 "\",0)", 419 "\",0)",
387 iframe_id.c_str(), url.spec().c_str()); 420 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 870 // Inject WebUI test runner script first prior to other scripts required to
838 // run the test as scripts may depend on it being declared. 871 // run the test as scripts may depend on it being declared.
839 std::vector<int> ids; 872 std::vector<int> ids;
840 ids.push_back(IDR_WEBUI_JS_WEBUI_RESOURCE_TEST); 873 ids.push_back(IDR_WEBUI_JS_WEBUI_RESOURCE_TEST);
841 ids.insert(ids.end(), js_resource_ids.begin(), js_resource_ids.end()); 874 ids.insert(ids.end(), js_resource_ids.begin(), js_resource_ids.end());
842 875
843 std::string script; 876 std::string script;
844 for (std::vector<int>::iterator iter = ids.begin(); 877 for (std::vector<int>::iterator iter = ids.begin();
845 iter != ids.end(); 878 iter != ids.end();
846 ++iter) { 879 ++iter) {
847 scoped_refptr<base::RefCountedMemory> resource = 880 scoped_refptr<base::RefCountedMemory> bytes =
848 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(*iter); 881 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(*iter);
849 script.append(resource->front_as<char>(), resource->size()); 882
883 if (HasGzipHeader(*bytes))
884 AppendGzippedResource(*bytes, &script);
885 else
886 script.append(bytes->front_as<char>(), bytes->size());
887
850 script.append("\n"); 888 script.append("\n");
851 } 889 }
852 if (!ExecuteScript(web_contents, script)) 890 if (!ExecuteScript(web_contents, script))
853 return false; 891 return false;
854 892
855 DOMMessageQueue message_queue; 893 DOMMessageQueue message_queue;
856 if (!ExecuteScript(web_contents, "runTests()")) 894 if (!ExecuteScript(web_contents, "runTests()"))
857 return false; 895 return false;
858 896
859 std::string message; 897 std::string message;
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 1689
1652 bool TestNavigationManager::ShouldMonitorNavigation(NavigationHandle* handle) { 1690 bool TestNavigationManager::ShouldMonitorNavigation(NavigationHandle* handle) {
1653 if (handle_ || handle->GetURL() != url_) 1691 if (handle_ || handle->GetURL() != url_)
1654 return false; 1692 return false;
1655 if (handled_navigation_) 1693 if (handled_navigation_)
1656 return false; 1694 return false;
1657 return true; 1695 return true;
1658 } 1696 }
1659 1697
1660 } // namespace content 1698 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/web_ui_data_source.h ('k') | net/filter/filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698