Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "base/command_line.h" | |
| 6 #include "base/memory/ptr_util.h" | |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 9 #include "chromeos/dbus/fake_media_analytics_client.h" | |
| 10 #include "chromeos/dbus/media_analytics_client.h" | |
| 11 #include "chromeos/media_perception/media_perception.pb.h" | |
| 12 #include "extensions/browser/api/media_perception_private/media_perception_priva te_api.h" | |
| 13 #include "extensions/common/switches.h" | |
| 14 #include "extensions/test/extension_test_message_listener.h" | |
| 15 | |
| 16 namespace extensions { | |
| 17 | |
| 18 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.
| |
| 19 public: | |
| 20 MediaPerceptionPrivateApiTest() {} | |
| 21 ~MediaPerceptionPrivateApiTest() override {} | |
| 22 | |
| 23 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 24 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 25 // Whitelist of the extension ID of the test extension. | |
| 26 command_line->AppendSwitchASCII( | |
| 27 extensions::switches::kWhitelistedExtensionID, | |
| 28 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | |
| 29 } | |
| 30 | |
| 31 void SetUp() override { | |
| 32 ExtensionApiTest::SetUp(); | |
| 33 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = | |
| 34 chromeos::DBusThreadManager::GetSetterForTesting(); | |
| 35 media_analytics_client_ = new chromeos::FakeMediaAnalyticsClient(); | |
| 36 dbus_setter->SetMediaAnalyticsClient( | |
| 37 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.
| |
| 38 } | |
| 39 | |
| 40 // Ownership is passed on to chromeos::DbusThreadManager. | |
| 41 chromeos::FakeMediaAnalyticsClient* media_analytics_client_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionPrivateApiTest); | |
| 44 }; | |
| 45 | |
| 46 // Verify that we can set and get mediaPerception system state. | |
| 47 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, State) { | |
| 48 ASSERT_TRUE(RunPlatformAppTest("media_perception_private/state")) << message_; | |
| 49 } | |
| 50 | |
| 51 // Verify that we can request Diagnostics. | |
| 52 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, GetDiagnostics) { | |
| 53 // Allows us to validate that the right data comes through the code path. | |
| 54 mri::Diagnostics diagnostics; | |
| 55 diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id( | |
| 56 1); | |
| 57 media_analytics_client_->SetDiagnostics(diagnostics); | |
| 58 | |
| 59 ASSERT_TRUE(RunPlatformAppTest("media_perception_private/diagnostics")) | |
| 60 << message_; | |
| 61 } | |
| 62 | |
| 63 // Verify that we can listen for MediaPerceptionDetection signals and handle | |
| 64 // them. | |
| 65 IN_PROC_BROWSER_TEST_F(MediaPerceptionPrivateApiTest, MediaPerception) { | |
| 66 ExtensionTestMessageListener handler_registered_listener( | |
| 67 "mediaPerceptionListenerSet", false); | |
| 68 ASSERT_TRUE(LoadExtension( | |
| 69 test_data_dir_.AppendASCII("media_perception_private/media_perception"))) | |
| 70 << message_; | |
| 71 ASSERT_TRUE(handler_registered_listener.WaitUntilSatisfied()); | |
| 72 | |
| 73 mri::MediaPerception media_perception; | |
| 74 media_perception.add_frame_perception()->set_frame_id(1); | |
| 75 ASSERT_TRUE( | |
| 76 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.
| |
| 77 } | |
| 78 | |
| 79 } // namespace extensions | |
| OLD | NEW |