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

Unified Diff: chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service_browsertest.cc

Issue 2808383004: Refactor and send voice interaction structure (Closed)
Patch Set: add test case Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service_browsertest.cc
diff --git a/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service_browsertest.cc b/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c74c3bfd2b51364c3bc2298e6addfaee8d0599d8
--- /dev/null
+++ b/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service_browsertest.cc
@@ -0,0 +1,89 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.h"
+
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/run_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/interactive_test_utils.h"
+#include "content/public/test/browser_test.h"
+#include "content/public/test/test_utils.h"
+#include "ui/accessibility/ax_tree_update.h"
+#include "ui/accessibility/platform/ax_snapshot_node_android_platform.h"
+
+namespace arc {
+
+namespace {
+
+class AXTreeSnapshotWaiter {
+ public:
+ AXTreeSnapshotWaiter() = default;
+
+ void Wait() { loop_.Run(); }
+
+ const ui::AXTreeUpdate& snapshot() const { return snapshot_; }
+
+ void ReceiveSnapshot(const ui::AXTreeUpdate& snapshot) {
+ snapshot_ = snapshot;
+ loop_.Quit();
+ }
+
+ private:
+ ui::AXTreeUpdate snapshot_;
+ base::RunLoop loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(AXTreeSnapshotWaiter);
+};
+
+} // namespace
+
+class ArcVoiceInteractionArcHomeServiceTest : public InProcessBrowserTest {
+ public:
+ ArcVoiceInteractionArcHomeServiceTest() = default;
+ ~ArcVoiceInteractionArcHomeServiceTest() override = default;
+
+ protected:
+ mojom::VoiceInteractionStructurePtr GetVoiceInteractionStructure(
+ const std::string& html) {
+ GURL url("data:text/html," + html);
+ ui_test_utils::NavigateToURL(browser(), url);
+ auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents();
+ AXTreeSnapshotWaiter waiter;
+ web_contents->RequestAXTreeSnapshot(base::Bind(
+ &AXTreeSnapshotWaiter::ReceiveSnapshot, base::Unretained(&waiter)));
+ waiter.Wait();
+ auto node = ui::AXSnapshotNodeAndroid::Create(waiter.snapshot());
+ return ArcVoiceInteractionArcHomeService::CreateVoiceInteractionStructure(
+ *node);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ArcVoiceInteractionArcHomeServiceTest);
+};
+
+IN_PROC_BROWSER_TEST_F(ArcVoiceInteractionArcHomeServiceTest,
+ VoiceInteractionStructurePositionTest) {
+ auto result = GetVoiceInteractionStructure(
+ "<div style='position:absolute;width:200px;height:200px'>"
+ "<p style='position:absolute;top:20px;left:20px;margin:0'>Hello</p>"
+ "</div>");
+ ASSERT_FALSE(result.is_null());
+ ASSERT_EQ(result->children.size(), 1ul);
+ ASSERT_EQ(result->children[0]->children.size(), 1ul);
+
+ auto& child = result->children[0]->children[0];
+ ASSERT_EQ(base::UTF16ToUTF8(child->text), "Hello");
+ ASSERT_EQ(child->rect.x(), 20);
+ ASSERT_EQ(child->rect.y(), 20);
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698