Index: extensions/browser/api/media_perception_private/media_perception_private_apitest.cc |
diff --git a/extensions/browser/api/media_perception_private/media_perception_private_apitest.cc b/extensions/browser/api/media_perception_private/media_perception_private_apitest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5d35eb8c699cfa36978bc3c89f6bdf2cdbebbc72 |
--- /dev/null |
+++ b/extensions/browser/api/media_perception_private/media_perception_private_apitest.cc |
@@ -0,0 +1,79 @@ |
+// 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 "base/command_line.h" |
+#include "base/memory/ptr_util.h" |
+#include "chrome/browser/extensions/extension_apitest.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/fake_media_analytics_client.h" |
+#include "chromeos/dbus/media_analytics_client.h" |
+#include "chromeos/media_perception/media_perception.pb.h" |
+#include "extensions/browser/api/media_perception_private/media_perception_private_api.h" |
+#include "extensions/common/switches.h" |
+#include "extensions/test/extension_test_message_listener.h" |
+ |
+namespace extensions { |
+ |
+class MediaPerceptionPrivateApiTest : public ExtensionApiTest { |
tbarzic
2017/05/12 18:59:20
please use https://cs.chromium.org/chromium/src/ex
Luke Sorenson
2017/05/12 21:56:21
Done.
|
+ public: |
+ MediaPerceptionPrivateApiTest() {} |
+ ~MediaPerceptionPrivateApiTest() override {} |
+ |
+ void SetUpCommandLine(base::CommandLine* command_line) override { |
+ ExtensionApiTest::SetUpCommandLine(command_line); |
+ // Whitelist of the extension ID of the test extension. |
+ command_line->AppendSwitchASCII( |
+ extensions::switches::kWhitelistedExtensionID, |
+ "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
+ } |
+ |
+ void SetUp() override { |
+ ExtensionApiTest::SetUp(); |
+ std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = |
+ chromeos::DBusThreadManager::GetSetterForTesting(); |
+ media_analytics_client_ = new chromeos::FakeMediaAnalyticsClient(); |
+ dbus_setter->SetMediaAnalyticsClient( |
+ base::WrapUnique(media_analytics_client_)); |
tbarzic
2017/05/12 19:52:10
both bare new and WrapUnique are discouraged in fa
Luke Sorenson
2017/05/12 21:56:21
Done.
|
+ } |
+ |
+ // Ownership is passed on to chromeos::DbusThreadManager. |
+ chromeos::FakeMediaAnalyticsClient* media_analytics_client_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaPerceptionPrivateApiTest); |
+}; |
+ |
+// Verify that we can set and get mediaPerception system state. |
+IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, State) { |
+ ASSERT_TRUE(RunPlatformAppTest("media_perception_private/state")) << message_; |
+} |
+ |
+// Verify that we can request Diagnostics. |
+IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, GetDiagnostics) { |
+ // Allows us to validate that the right data comes through the code path. |
+ mri::Diagnostics diagnostics; |
+ diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id( |
+ 1); |
+ media_analytics_client_->SetDiagnostics(diagnostics); |
+ |
+ ASSERT_TRUE(RunPlatformAppTest("media_perception_private/diagnostics")) |
+ << message_; |
+} |
+ |
+// Verify that we can listen for MediaPerceptionDetection signals and handle |
+// them. |
+IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, MediaPerception) { |
+ ExtensionTestMessageListener handler_registered_listener( |
+ "mediaPerceptionListenerSet", false); |
+ ASSERT_TRUE(LoadExtension( |
+ test_data_dir_.AppendASCII("media_perception_private/media_perception"))) |
+ << message_; |
+ ASSERT_TRUE(handler_registered_listener.WaitUntilSatisfied()); |
+ |
+ mri::MediaPerception media_perception; |
+ media_perception.add_frame_perception()->set_frame_id(1); |
+ ASSERT_TRUE( |
+ media_analytics_client_->FireMediaPerceptionEvent(media_perception)); |
tbarzic
2017/05/12 19:52:10
you have to wait for the apitest to send test resu
Luke Sorenson
2017/05/12 21:56:21
Done.
|
+} |
+ |
+} // namespace extensions |