OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/dom_distiller/core/distiller.h" | 13 #include "components/dom_distiller/core/distiller.h" |
14 #include "components/dom_distiller/core/distiller_page.h" | 14 #include "components/dom_distiller/core/distiller_page.h" |
15 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 15 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
16 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/base/resource/resource_bundle.h" | |
20 | 19 |
21 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
22 #include "base/android/jni_android.h" | 21 #include "base/android/jni_android.h" |
23 #include "ui/base/android/ui_base_jni_registrar.h" | 22 #include "ui/base/android/ui_base_jni_registrar.h" |
24 #include "ui/gfx/android/gfx_jni_registrar.h" | 23 #include "ui/gfx/android/gfx_jni_registrar.h" |
25 #endif | 24 #endif |
26 | 25 |
27 using::testing::Invoke; | 26 using::testing::Invoke; |
28 using::testing::Return; | 27 using::testing::Return; |
29 using::testing::_; | 28 using::testing::_; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 132 } |
134 | 133 |
135 TEST_F(DistillerTest, DistillPage) { | 134 TEST_F(DistillerTest, DistillPage) { |
136 #if defined(OS_ANDROID) | 135 #if defined(OS_ANDROID) |
137 // Register JNI bindings for android. | 136 // Register JNI bindings for android. |
138 JNIEnv* env = base::android::AttachCurrentThread(); | 137 JNIEnv* env = base::android::AttachCurrentThread(); |
139 gfx::android::RegisterJni(env); | 138 gfx::android::RegisterJni(env); |
140 ui::android::RegisterJni(env); | 139 ui::android::RegisterJni(env); |
141 #endif | 140 #endif |
142 | 141 |
143 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); | |
144 base::MessageLoop loop(base::MessageLoop::TYPE_UI); | 142 base::MessageLoop loop(base::MessageLoop::TYPE_UI); |
145 scoped_ptr<base::ListValue> list(new base::ListValue()); | 143 scoped_ptr<base::ListValue> list(new base::ListValue()); |
146 list->AppendString(kTitle); | 144 list->AppendString(kTitle); |
147 list->AppendString(kContent); | 145 list->AppendString(kContent); |
148 list->AppendString(kImageURL0); | 146 list->AppendString(kImageURL0); |
149 list->AppendString(kImageURL1); | 147 list->AppendString(kImageURL1); |
150 EXPECT_CALL(page_factory_, | 148 EXPECT_CALL(page_factory_, |
151 CreateDistillerPageMock(_)).WillOnce( | 149 CreateDistillerPageMock(_)).WillOnce( |
152 CreateMockDistillerPage(list.get(), GURL(kURL))); | 150 CreateMockDistillerPage(list.get(), GURL(kURL))); |
153 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_)); | 151 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_)); |
154 distiller_->Init(); | 152 distiller_->Init(); |
155 distiller_->DistillPage( | 153 distiller_->DistillPage( |
156 GURL(kURL), | 154 GURL(kURL), |
157 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this))); | 155 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this))); |
158 base::MessageLoop::current()->RunUntilIdle(); | 156 base::MessageLoop::current()->RunUntilIdle(); |
159 EXPECT_EQ(kTitle, proto_->title()); | 157 EXPECT_EQ(kTitle, proto_->title()); |
160 EXPECT_EQ(kContent, proto_->html()); | 158 EXPECT_EQ(kContent, proto_->html()); |
161 EXPECT_EQ(kURL, proto_->url()); | 159 EXPECT_EQ(kURL, proto_->url()); |
162 EXPECT_EQ(2, proto_->image_size()); | 160 EXPECT_EQ(2, proto_->image_size()); |
163 EXPECT_EQ(kImageData0, proto_->image(0).data()); | 161 EXPECT_EQ(kImageData0, proto_->image(0).data()); |
164 EXPECT_EQ(kId0, proto_->image(0).name()); | 162 EXPECT_EQ(kId0, proto_->image(0).name()); |
165 EXPECT_EQ(kImageData1, proto_->image(1).data()); | 163 EXPECT_EQ(kImageData1, proto_->image(1).data()); |
166 EXPECT_EQ(kId1, proto_->image(1).name()); | 164 EXPECT_EQ(kId1, proto_->image(1).name()); |
167 } | 165 } |
168 | 166 |
169 } // namespace dom_distiller | 167 } // namespace dom_distiller |
OLD | NEW |