Bug 1511267 - Cloud Storage init provider test and intermittent failure fix r=jaws
authorPunam <pdahiya@mozilla.com>
Tue, 15 Jan 2019 21:50:17 +0000
changeset 511097 d94c4b92b44b313a48c3581d6804950f1235b7cb
parent 511096 4ee8f7951ed5cb5fe9b4955dae15e1ca9d6be9c6
child 511098 903466ee22ee9019b7c26f978fc8b676f12339fb
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1511267
milestone66.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 1511267 - Cloud Storage init provider test and intermittent failure fix r=jaws Cloud Storage initialize provider test to help fix intermittent test failures Differential Revision: https://phabricator.services.mozilla.com/D15998
browser/components/preferences/in-content/tests/browser_cloud_storage.js
--- a/browser/components/preferences/in-content/tests/browser_cloud_storage.js
+++ b/browser/components/preferences/in-content/tests/browser_cloud_storage.js
@@ -1,24 +1,21 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
+ChromeUtils.defineModuleGetter(this, "CloudStorage",
+                               "resource://gre/modules/CloudStorage.jsm");
 ChromeUtils.defineModuleGetter(this, "FileUtils",
                                "resource://gre/modules/FileUtils.jsm");
-ChromeUtils.defineModuleGetter(this, "NetUtil",
-                               "resource://gre/modules/NetUtil.jsm");
 
 const DROPBOX_DOWNLOAD_FOLDER = "Dropbox";
-const DROPBOX_CONFIG_FOLDER = (AppConstants.platform === "win") ? "Dropbox" :
-                                                                  ".dropbox";
-const DROPBOX_KEY = "Dropbox";
 const CLOUD_SERVICES_PREF = "cloud.services.";
 
 function create_subdir(dir, subdirname) {
   let subdir = dir.clone();
   subdir.append(subdirname);
   if (subdir.exists()) {
     subdir.remove(true);
   }
@@ -55,70 +52,54 @@ function registerFakePath(key, folderNam
     dirsvc.undefine(key);
     if (originalFile) {
       dirsvc.set(key, originalFile);
     }
   });
 }
 
 async function mock_dropbox() {
-  let discoveryFile = null;
-  if (AppConstants.platform === "win") {
-    discoveryFile = FileUtils.getFile("LocalAppData", [DROPBOX_CONFIG_FOLDER]);
-  } else {
-    discoveryFile = FileUtils.getFile("Home", [DROPBOX_CONFIG_FOLDER]);
-  }
-  discoveryFile.append("info.json");
-  if (!discoveryFile.exists()) {
-    discoveryFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
-  }
-  console.log(discoveryFile.path);
   // Mock Dropbox Download folder in Home directory
   let downloadFolder = FileUtils.getFile("Home", [DROPBOX_DOWNLOAD_FOLDER, "Downloads"]);
   if (!downloadFolder.exists()) {
     downloadFolder.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
   }
   console.log(downloadFolder.path);
 
   registerCleanupFunction(() => {
-    if (discoveryFile.exists()) {
-      discoveryFile.remove(true);
-    }
     if (downloadFolder.exists()) {
       downloadFolder.remove(true);
     }
   });
-
-  let data = '{"personal": {"path": "Test"}}';
-  let ostream = FileUtils.openSafeFileOutputStream(discoveryFile);
-  let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
-                  createInstance(Ci.nsIScriptableUnicodeConverter);
-  converter.charset = "UTF-8";
-  let istream = converter.convertToInputStream(data);
-  return new Promise(resolve => {
-    NetUtil.asyncCopy(istream, ostream, resolve);
-  });
 }
 
 add_task(async function setup() {
-  // Create mock Dropbox discovery and download folder for cloudstorage API
-  // to detect dropbox provider app
+  // Create mock Dropbox download folder for cloudstorage API
   // Set prefs required to display second radio option
   // 'Save to Dropbox' under Downloads
+  let folderName = "CloudStorage";
+  registerFakePath("Home", folderName);
+  await mock_dropbox();
   await SpecialPowers.pushPrefEnv({set: [
     [CLOUD_SERVICES_PREF + "api.enabled", true],
     [CLOUD_SERVICES_PREF + "storage.key", "Dropbox"],
   ]});
+});
 
-  let folderName = "CloudStorage";
-  registerFakePath("Home", folderName);
-  registerFakePath("LocalAppData", folderName);
-  let status = await mock_dropbox();
-  ok(Components.isSuccessCode(status),
-    "Cloud Storage: dropbox mockup should be created successfully. status: " + status);
+add_task(async function test_initProvider() {
+  // Get preferred provider key
+  let preferredProvider = await CloudStorage.getPreferredProvider();
+  is(preferredProvider, "Dropbox", "Cloud Storage preferred provider key");
+
+  let isInitialized = await CloudStorage.init();
+  is(isInitialized, true, "Providers Metadata successfully initialized");
+
+  // Get preferred provider in use display name
+  let providerDisplayName = await CloudStorage.getProviderIfInUse();
+  is(providerDisplayName, "Dropbox", "Cloud Storage preferred provider display name");
 });
 
 add_task(async function() {
   await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
   let doc = gBrowser.selectedBrowser.contentDocument;
   let saveWhereOptions = doc.getElementById("saveWhere");
   let saveToCloud = doc.getElementById("saveToCloud");
   is(saveWhereOptions.itemCount, 3, "Radio options count");