OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/http/http_request_headers.h" | |
10 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
16 #include "webkit/glue/media/buffered_resource_loader.h" | 18 #include "webkit/glue/media/buffered_resource_loader.h" |
17 #include "webkit/mocks/mock_webframeclient.h" | 19 #include "webkit/mocks/mock_webframeclient.h" |
18 #include "webkit/mocks/mock_weburlloader.h" | 20 #include "webkit/mocks/mock_weburlloader.h" |
19 | 21 |
20 using ::testing::_; | 22 using ::testing::_; |
21 using ::testing::Assign; | 23 using ::testing::Assign; |
22 using ::testing::AtLeast; | 24 using ::testing::AtLeast; |
23 using ::testing::DeleteArg; | 25 using ::testing::DeleteArg; |
24 using ::testing::DoAll; | 26 using ::testing::DoAll; |
25 using ::testing::InSequence; | 27 using ::testing::InSequence; |
26 using ::testing::Invoke; | 28 using ::testing::Invoke; |
27 using ::testing::InvokeWithoutArgs; | 29 using ::testing::InvokeWithoutArgs; |
28 using ::testing::NotNull; | 30 using ::testing::NotNull; |
29 using ::testing::Return; | 31 using ::testing::Return; |
30 using ::testing::ReturnRef; | 32 using ::testing::ReturnRef; |
31 using ::testing::SetArgumentPointee; | 33 using ::testing::SetArgumentPointee; |
32 using ::testing::StrictMock; | 34 using ::testing::StrictMock; |
35 using ::testing::Truly; | |
33 using ::testing::NiceMock; | 36 using ::testing::NiceMock; |
34 using ::testing::WithArgs; | 37 using ::testing::WithArgs; |
35 | 38 |
36 using WebKit::WebString; | 39 using WebKit::WebString; |
37 using WebKit::WebURLError; | 40 using WebKit::WebURLError; |
38 using WebKit::WebURLResponse; | 41 using WebKit::WebURLResponse; |
39 using WebKit::WebView; | 42 using WebKit::WebView; |
40 | 43 |
41 namespace webkit_glue { | 44 namespace webkit_glue { |
42 | 45 |
(...skipping 15 matching lines...) Expand all Loading... | |
58 | 61 |
59 // Submit a request completed event to the resource loader due to request | 62 // Submit a request completed event to the resource loader due to request |
60 // being canceled. Pretending the event is from external. | 63 // being canceled. Pretending the event is from external. |
61 ACTION_P(RequestCanceled, loader) { | 64 ACTION_P(RequestCanceled, loader) { |
62 WebURLError error; | 65 WebURLError error; |
63 error.reason = net::ERR_ABORTED; | 66 error.reason = net::ERR_ABORTED; |
64 error.domain = WebString::fromUTF8(net::kErrorDomain); | 67 error.domain = WebString::fromUTF8(net::kErrorDomain); |
65 loader->didFail(NULL, error); | 68 loader->didFail(NULL, error); |
66 } | 69 } |
67 | 70 |
71 // Predicate that tests that request disallows compressed data. | |
72 static bool CorrectAcceptEncoding(const WebKit::WebURLRequest &request) { | |
73 WebKit::WebString value = request.httpHeaderField( | |
74 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)); | |
75 return value == WebString::fromUTF8("identity;q=1, *;q=0"); | |
Alpha Left Google
2011/06/09 20:30:25
Check the exact string in the implementation is to
enal
2011/06/09 21:55:03
Done.
| |
76 } | |
77 | |
68 class BufferedResourceLoaderTest : public testing::Test { | 78 class BufferedResourceLoaderTest : public testing::Test { |
69 public: | 79 public: |
70 BufferedResourceLoaderTest() | 80 BufferedResourceLoaderTest() |
71 : view_(WebView::create(NULL)) { | 81 : view_(WebView::create(NULL)) { |
72 view_->initializeMainFrame(&client_); | 82 view_->initializeMainFrame(&client_); |
73 | 83 |
74 for (int i = 0; i < kDataSize; ++i) { | 84 for (int i = 0; i < kDataSize; ++i) { |
75 data_[i] = i; | 85 data_[i] = i; |
76 } | 86 } |
77 } | 87 } |
(...skipping 13 matching lines...) Expand all Loading... | |
91 loader_->SetURLLoaderForTest(url_loader_); | 101 loader_->SetURLLoaderForTest(url_loader_); |
92 } | 102 } |
93 | 103 |
94 void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) { | 104 void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) { |
95 loader_->buffer_.reset( | 105 loader_->buffer_.reset( |
96 new media::SeekableBuffer(backward_capacity, forward_capacity)); | 106 new media::SeekableBuffer(backward_capacity, forward_capacity)); |
97 } | 107 } |
98 | 108 |
99 void Start() { | 109 void Start() { |
100 InSequence s; | 110 InSequence s; |
101 EXPECT_CALL(*url_loader_, loadAsynchronously(_, loader_.get())); | 111 EXPECT_CALL(*url_loader_, loadAsynchronously(Truly(CorrectAcceptEncoding), |
112 loader_.get())); | |
102 loader_->Start( | 113 loader_->Start( |
103 NewCallback(this, &BufferedResourceLoaderTest::StartCallback), | 114 NewCallback(this, &BufferedResourceLoaderTest::StartCallback), |
104 NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback), | 115 NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback), |
105 view_->mainFrame()); | 116 view_->mainFrame()); |
106 } | 117 } |
107 | 118 |
108 void FullResponse(int64 instance_size) { | 119 void FullResponse(int64 instance_size) { |
109 FullResponse(instance_size, net::OK); | 120 FullResponse(instance_size, net::OK); |
110 } | 121 } |
111 | 122 |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 Start(); | 589 Start(); |
579 Redirect(kHttpRedirectToSameDomainUrl1); | 590 Redirect(kHttpRedirectToSameDomainUrl1); |
580 Redirect(kHttpRedirectToDifferentDomainUrl1); | 591 Redirect(kHttpRedirectToDifferentDomainUrl1); |
581 EXPECT_FALSE(loader_->HasSingleOrigin()); | 592 EXPECT_FALSE(loader_->HasSingleOrigin()); |
582 StopWhenLoad(); | 593 StopWhenLoad(); |
583 } | 594 } |
584 | 595 |
585 // TODO(hclam): add unit test for defer loading. | 596 // TODO(hclam): add unit test for defer loading. |
586 | 597 |
587 } // namespace webkit_glue | 598 } // namespace webkit_glue |
OLD | NEW |