| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/base/sdch_dictionary_fetcher.h" | 5 #include "net/base/sdch_dictionary_fetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 url.spec().c_str()); | 55 url.spec().c_str()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static int jobs_requested() { return jobs_requested_; } | 58 static int jobs_requested() { return jobs_requested_; } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 virtual ~URLRequestSpecifiedResponseJob() {}; | 61 virtual ~URLRequestSpecifiedResponseJob() {}; |
| 62 virtual int GetData(std::string* mime_type, | 62 virtual int GetData(std::string* mime_type, |
| 63 std::string* charset, | 63 std::string* charset, |
| 64 std::string* data, | 64 std::string* data, |
| 65 const CompletionCallback& callback) const OVERRIDE { | 65 const CompletionCallback& callback) const override { |
| 66 GURL url(request_->url()); | 66 GURL url(request_->url()); |
| 67 *data = ExpectedResponseForURL(url); | 67 *data = ExpectedResponseForURL(url); |
| 68 return OK; | 68 return OK; |
| 69 } | 69 } |
| 70 | 70 |
| 71 static int jobs_requested_; | 71 static int jobs_requested_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 int URLRequestSpecifiedResponseJob::jobs_requested_(0); | 74 int URLRequestSpecifiedResponseJob::jobs_requested_(0); |
| 75 | 75 |
| 76 class SdchTestDelegate : public SdchFetcher::Delegate { | 76 class SdchTestDelegate : public SdchFetcher::Delegate { |
| 77 public: | 77 public: |
| 78 struct DictionaryAdditions { | 78 struct DictionaryAdditions { |
| 79 DictionaryAdditions(const std::string& dictionary_text, | 79 DictionaryAdditions(const std::string& dictionary_text, |
| 80 const GURL& dictionary_url) | 80 const GURL& dictionary_url) |
| 81 : dictionary_text(dictionary_text), | 81 : dictionary_text(dictionary_text), |
| 82 dictionary_url(dictionary_url) {} | 82 dictionary_url(dictionary_url) {} |
| 83 | 83 |
| 84 | 84 |
| 85 std::string dictionary_text; | 85 std::string dictionary_text; |
| 86 GURL dictionary_url; | 86 GURL dictionary_url; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 virtual void AddSdchDictionary(const std::string& dictionary_text, | 89 virtual void AddSdchDictionary(const std::string& dictionary_text, |
| 90 const GURL& dictionary_url) OVERRIDE { | 90 const GURL& dictionary_url) override { |
| 91 dictionary_additions.push_back( | 91 dictionary_additions.push_back( |
| 92 DictionaryAdditions(dictionary_text, dictionary_url)); | 92 DictionaryAdditions(dictionary_text, dictionary_url)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void GetDictionaryAdditions(std::vector<DictionaryAdditions>* out) { | 95 void GetDictionaryAdditions(std::vector<DictionaryAdditions>* out) { |
| 96 out->swap(dictionary_additions); | 96 out->swap(dictionary_additions); |
| 97 dictionary_additions.clear(); | 97 dictionary_additions.clear(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 std::vector<DictionaryAdditions> dictionary_additions; | 101 std::vector<DictionaryAdditions> dictionary_additions; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 class SdchDictionaryFetcherTest : public ::testing::Test { | 104 class SdchDictionaryFetcherTest : public ::testing::Test { |
| 105 public: | 105 public: |
| 106 SdchDictionaryFetcherTest() {} | 106 SdchDictionaryFetcherTest() {} |
| 107 | 107 |
| 108 virtual void SetUp() OVERRIDE { | 108 virtual void SetUp() override { |
| 109 DCHECK(!fetcher_.get()); | 109 DCHECK(!fetcher_.get()); |
| 110 | 110 |
| 111 URLRequestSpecifiedResponseJob::AddUrlHandler(); | 111 URLRequestSpecifiedResponseJob::AddUrlHandler(); |
| 112 fetcher_delegate_.reset(new SdchTestDelegate); | 112 fetcher_delegate_.reset(new SdchTestDelegate); |
| 113 context_.reset(new TestURLRequestContext); | 113 context_.reset(new TestURLRequestContext); |
| 114 fetcher_.reset(new SdchDictionaryFetcher( | 114 fetcher_.reset(new SdchDictionaryFetcher( |
| 115 fetcher_delegate_.get(), context_.get())); | 115 fetcher_delegate_.get(), context_.get())); |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual void TearDown() OVERRIDE { | 118 virtual void TearDown() override { |
| 119 URLRequestSpecifiedResponseJob::RemoveUrlHandler(); | 119 URLRequestSpecifiedResponseJob::RemoveUrlHandler(); |
| 120 fetcher_.reset(); | 120 fetcher_.reset(); |
| 121 context_.reset(); | 121 context_.reset(); |
| 122 fetcher_delegate_.reset(); | 122 fetcher_delegate_.reset(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 SdchDictionaryFetcher* fetcher() { return fetcher_.get(); } | 125 SdchDictionaryFetcher* fetcher() { return fetcher_.get(); } |
| 126 SdchTestDelegate* manager() { return fetcher_delegate_.get(); } | 126 SdchTestDelegate* manager() { return fetcher_delegate_.get(); } |
| 127 | 127 |
| 128 // May not be called outside the SetUp()/TearDown() interval. | 128 // May not be called outside the SetUp()/TearDown() interval. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 fetcher()->Schedule(dictionary_url_2); | 184 fetcher()->Schedule(dictionary_url_2); |
| 185 fetcher()->Schedule(dictionary_url_3); | 185 fetcher()->Schedule(dictionary_url_3); |
| 186 fetcher()->Cancel(); | 186 fetcher()->Cancel(); |
| 187 base::RunLoop().RunUntilIdle(); | 187 base::RunLoop().RunUntilIdle(); |
| 188 | 188 |
| 189 // Synchronous execution may have resulted in a single job being scheduled. | 189 // Synchronous execution may have resulted in a single job being scheduled. |
| 190 EXPECT_GE(1, JobsRequested()); | 190 EXPECT_GE(1, JobsRequested()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 } | 193 } |
| OLD | NEW |