[GCM] Add support for extra large data packets
[chromium-blink-merge.git] / components / html_viewer / ax_provider_apptest.cc
bloba4e8cb0a341ef3538bac2cc761326f6bd56a3bb8
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.
5 #include "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/test/test_timeouts.h"
10 #include "components/view_manager/public/cpp/tests/view_manager_test_base.h"
11 #include "components/view_manager/public/cpp/view.h"
12 #include "components/view_manager/public/cpp/view_manager.h"
13 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
14 #include "mojo/application/public/cpp/application_impl.h"
15 #include "mojo/application/public/cpp/application_test_base.h"
16 #include "net/test/spawned_test_server/spawned_test_server.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessibility.mojom.h"
20 namespace mojo {
22 namespace {
24 // Returns true if the tree contains a text node with contents matching |text|.
25 bool AxTreeContainsText(const Array<AxNodePtr>& tree, const String& text) {
26 for (size_t i = 0; i < tree.size(); ++i) {
27 if (!tree[i]->text.is_null() && tree[i]->text->content == text)
28 return true;
30 return false;
33 // Switch to enable out of process iframes.
34 const char kOOPIF[] = "oopifs";
36 bool EnableOOPIFs() {
37 return base::CommandLine::ForCurrentProcess()->HasSwitch(kOOPIF);
40 class TestFrameTreeServer : public mandoline::FrameTreeServer {
41 public:
42 TestFrameTreeServer() {}
43 ~TestFrameTreeServer() override {}
45 // mandoline::FrameTreeServer:
46 void PostMessageEventToFrame(uint32_t frame_id,
47 mandoline::MessageEventPtr event) override {}
48 void NavigateFrame(uint32_t frame_id) override {}
49 void ReloadFrame(uint32_t frame_id) override {}
51 private:
52 DISALLOW_COPY_AND_ASSIGN(TestFrameTreeServer);
55 } // namespace
57 using AXProviderTest = ViewManagerTestBase;
59 TEST_F(AXProviderTest, HelloWorld) {
60 // TODO(msw|sky): Fix flaky timeouts without oopifs; http://crbug.com/504917
61 if (!EnableOOPIFs())
62 return;
64 // Start a test server for net/data/test.html access.
65 net::SpawnedTestServer server(
66 net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost,
67 base::FilePath(FILE_PATH_LITERAL("net/data")));
68 ASSERT_TRUE(server.Start());
70 // Connect to the URL through the mojo:html_viewer content handler.
71 const uint16_t assigned_port = server.host_port_pair().port();
72 mojo::URLRequestPtr request(mojo::URLRequest::New());
73 request->url = mojo::String::From(
74 base::StringPrintf("http://127.0.0.1:%u/files/test.html", assigned_port));
75 ApplicationConnection* connection = application_impl()->ConnectToApplication(
76 request.Pass());
78 // Embed the html_viewer in a View.
79 ViewManagerClientPtr view_manager_client;
80 connection->ConnectToService(&view_manager_client);
81 View* embed_view = window_manager()->CreateView();
82 embed_view->Embed(view_manager_client.Pass());
84 if (EnableOOPIFs()) {
85 TestFrameTreeServer frame_tree_server;
86 mandoline::FrameTreeServerPtr frame_tree_server_ptr;
87 mojo::Binding<mandoline::FrameTreeServer> frame_tree_server_binding(
88 &frame_tree_server);
89 frame_tree_server_binding.Bind(GetProxy(&frame_tree_server_ptr).Pass());
91 mojo::Array<mandoline::FrameDataPtr> array(1u);
92 array[0] = mandoline::FrameData::New().Pass();
93 array[0]->frame_id = embed_view->id();
94 array[0]->parent_id = 0u;
96 mandoline::FrameTreeClientPtr frame_tree_client;
97 connection->ConnectToService(&frame_tree_client);
98 frame_tree_client->OnConnect(frame_tree_server_ptr.Pass(), array.Pass());
101 // Connect to the AxProvider of the HTML document and get the AxTree.
102 AxProviderPtr ax_provider;
103 connection->ConnectToService(&ax_provider);
104 Array<AxNodePtr> ax_tree;
105 ax_provider->GetTree([&ax_tree](Array<AxNodePtr> tree) {
106 ax_tree = tree.Pass();
107 EXPECT_TRUE(QuitRunLoop());
109 ASSERT_TRUE(DoRunLoopWithTimeout());
111 EXPECT_TRUE(AxTreeContainsText(ax_tree, "Hello "));
112 EXPECT_TRUE(AxTreeContainsText(ax_tree, "World!"));
113 EXPECT_FALSE(AxTreeContainsText(ax_tree, "foo"));
116 } // namespace mojo