Bug 1194112. Part 6 - add a test case to test the exclusive mode. r=kinetik.
☠☠ backed out by 2b568650c03a ☠ ☠
authorJW Wang <jwwang@mozilla.com>
Tue, 18 Aug 2015 11:12:18 +0800
changeset 258134 d0eee19c83cd9b2130c11eeea832dbceeafa37a9
parent 258133 0c54ee53678f9efd84330945e45b3a1349c54e71
child 258135 01bca969ceda5e6ded11cef25f9c8d5f4794f9f7
push id63830
push userjwwang@mozilla.com
push dateTue, 18 Aug 2015 07:11:16 +0000
treeherdermozilla-inbound@d0eee19c83cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1194112
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1194112. Part 6 - add a test case to test the exclusive mode. r=kinetik.
dom/media/gtest/TestMediaEventSource.cpp
--- a/dom/media/gtest/TestMediaEventSource.cpp
+++ b/dom/media/gtest/TestMediaEventSource.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gtest/gtest.h"
 
 #include "mozilla/TaskQueue.h"
+#include "mozilla/UniquePtr.h"
 #include "MediaEventSource.h"
 #include "VideoUtils.h"
 
 using namespace mozilla;
 
 /*
  * Test if listeners receive the event data correctly.
  */
@@ -289,8 +290,34 @@ TEST(MediaEventSource, CopyEvent2)
   source.Notify(SomeEvent(i));
 
   queue->BeginShutdown();
   queue->AwaitShutdownAndIdle();
   EXPECT_EQ(i, 0);
   listener1.Disconnect();
   listener2.Disconnect();
 }
+
+/*
+ * Test move-only types.
+ */
+TEST(MediaEventSource, MoveOnly)
+{
+  nsRefPtr<TaskQueue> queue = new TaskQueue(
+    GetMediaThreadPool(MediaThreadType::PLAYBACK));
+
+  MediaEventProducer<UniquePtr<int>, ListenerMode::Exclusive> source;
+
+  auto func = [] (UniquePtr<int>&& aEvent) {
+    EXPECT_EQ(*aEvent, 20);
+  };
+  MediaEventListener listener = source.Connect(queue, func);
+
+  // It is OK to pass an rvalue which is move-only.
+  source.Notify(UniquePtr<int>(new int(20)));
+  // It is an error to pass an lvalue which is move-only.
+  // UniquePtr<int> event(new int(30));
+  // source.Notify(event);
+
+  queue->BeginShutdown();
+  queue->AwaitShutdownAndIdle();
+  listener.Disconnect();
+}