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

Side by Side Diff: ios/web/webui/url_fetcher_block_adapter_unittest.mm

Issue 1110213002: Upstream most of the iOS WebUI support in ios/web/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "ios/web/webui/url_fetcher_block_adapter.h"
6
7 #include <string>
8
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "net/url_request/test_url_fetcher_factory.h"
13 #include "net/url_request/url_request_status.h"
14 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gtest_mac.h"
16 #include "testing/platform_test.h"
17 #include "url/gurl.h"
18
19 namespace web {
20
21 // Test fixture for URLFetcherBlockAdapter.
22 class URLFetcherBlockAdapterTest : public PlatformTest {
23 protected:
24 // Required for base::MessageLoop::current().
25 base::MessageLoopForUI loop_;
26 };
27
28 // Tests that URLFetcherBlockAdapter calls its completion handler with the
29 // appropriate data for a text resource.
30 TEST_F(URLFetcherBlockAdapterTest, FetchTextResource) {
31 GURL test_url("http://test");
32 std::string response("<html><body>Hello World!</body></html>");
33 NSData* expected_data =
34 [NSData dataWithBytes:response.c_str() length:response.size()];
35 web::URLFetcherBlockAdapterCompletion completion_handler =
36 ^(NSData* data, web::URLFetcherBlockAdapter* fetcher) {
37 EXPECT_NSEQ(expected_data, data);
38 };
39 web::URLFetcherBlockAdapter web_ui_fetcher(test_url, nil, completion_handler);
40 net::FakeURLFetcher fake_fetcher(test_url, &web_ui_fetcher, response,
41 net::HTTP_OK,
42 net::URLRequestStatus::SUCCESS);
43 fake_fetcher.Start();
44 base::MessageLoop::current()->RunUntilIdle();
45 }
46
47 // Tests that URLFetcherBlockAdapter calls its completion handler with the
48 // appropriate data for a png resource.
49 TEST_F(URLFetcherBlockAdapterTest, FetchPNGResource) {
50 GURL test_url("http://test");
51 base::FilePath favicon_path;
52 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &favicon_path));
53 favicon_path = favicon_path.AppendASCII("ios/web/test/data/testfavicon.png");
54 NSData* expected_data = [NSData
55 dataWithContentsOfFile:base::SysUTF8ToNSString(favicon_path.value())];
56 web::URLFetcherBlockAdapterCompletion completion_handler =
57 ^(NSData* data, URLFetcherBlockAdapter* fetcher) {
58 EXPECT_NSEQ(expected_data, data);
59 };
60 web::URLFetcherBlockAdapter web_ui_fetcher(test_url, nil, completion_handler);
61 std::string response;
62 EXPECT_TRUE(ReadFileToString(favicon_path, &response));
63 net::FakeURLFetcher fake_fetcher(test_url, &web_ui_fetcher, response,
64 net::HTTP_OK,
65 net::URLRequestStatus::SUCCESS);
66 fake_fetcher.Start();
67 base::MessageLoop::current()->RunUntilIdle();
68 }
69
70 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698