Bug 1249438 P2 Modify existing gtest to use RegisterServiceWorkerInternal. r=baku
authorBen Kelly <ben@wanderview.com>
Tue, 29 Mar 2016 07:20:48 -0700
changeset 290934 af6b4f4f55cb0c237c66be379dbd8344725f9136
parent 290933 580604cd40cb0b298287383659035d2ee52d5266
child 290935 8b7a2b89ff39d5943ebc6b439f769a74dd38f3d3
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1249438
milestone48.0a1
Bug 1249438 P2 Modify existing gtest to use RegisterServiceWorkerInternal. r=baku
dom/workers/test/gtest/TestReadWrite.cpp
--- a/dom/workers/test/gtest/TestReadWrite.cpp
+++ b/dom/workers/test/gtest/TestReadWrite.cpp
@@ -9,16 +9,17 @@
 #include "mozilla/dom/ServiceWorkerRegistrar.h"
 #include "mozilla/dom/ServiceWorkerRegistrarTypes.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
 
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsIFile.h"
 #include "nsIOutputStream.h"
 #include "nsNetUtil.h"
+#include "nsPrintfCString.h"
 
 using namespace mozilla::dom;
 using namespace mozilla::ipc;
 
 class ServiceWorkerRegistrarTest : public ServiceWorkerRegistrar
 {
 public:
   ServiceWorkerRegistrarTest()
@@ -29,16 +30,21 @@ public:
       return;
     }
   }
 
   nsresult TestReadData() { return ReadData(); }
   nsresult TestWriteData() { return WriteData(); }
   void TestDeleteData() { DeleteData(); }
 
+  void TestRegisterServiceWorker(const ServiceWorkerRegistrationData& aData)
+  {
+    RegisterServiceWorkerInternal(aData);
+  }
+
   nsTArray<ServiceWorkerRegistrationData>& TestGetData() { return mData; }
 };
 
 already_AddRefed<nsIFile>
 GetFile()
 {
   nsCOMPtr<nsIFile> file;
   nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
@@ -203,27 +209,30 @@ TEST(ServiceWorkerRegistrar, TestDeleteD
   ASSERT_FALSE(exists) << "The file should not exist after a DeleteData().";
 }
 
 TEST(ServiceWorkerRegistrar, TestWriteData)
 {
   {
     RefPtr<ServiceWorkerRegistrarTest> swr = new ServiceWorkerRegistrarTest;
 
-    nsTArray<ServiceWorkerRegistrationData>& data = swr->TestGetData();
+    for (int i = 0; i < 10; ++i) {
+      ServiceWorkerRegistrationData reg;
 
-    for (int i = 0; i < 10; ++i) {
-      ServiceWorkerRegistrationData* d = data.AppendElement();
+      reg.scope() = nsPrintfCString("scope write %d", i);
+      reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i);
+      reg.cacheName() =
+        NS_ConvertUTF8toUTF16(nsPrintfCString("cacheName write %d", i));
 
       nsAutoCString spec;
       spec.AppendPrintf("spec write %d", i);
-      d->principal() = mozilla::ipc::ContentPrincipalInfo(mozilla::PrincipalOriginAttributes(i, i % 2), spec);
-      d->scope().AppendPrintf("scope write %d", i);
-      d->currentWorkerURL().AppendPrintf("currentWorkerURL write %d", i);
-      d->cacheName().AppendPrintf("cacheName write %d", i);
+      reg.principal() =
+        mozilla::ipc::ContentPrincipalInfo(mozilla::PrincipalOriginAttributes(i, i % 2), spec);
+
+      swr->TestRegisterServiceWorker(reg);
     }
 
     nsresult rv = swr->TestWriteData();
     ASSERT_EQ(NS_OK, rv) << "WriteData() should not fail";
   }
 
   RefPtr<ServiceWorkerRegistrarTest> swr = new ServiceWorkerRegistrarTest;