Esempio n. 1
0
  public void updateUserPrefs() {
    if (port == 0) {
      throw new WebDriverException("You must set the port to listen on before updating user.js");
    }

    Map<String, String> prefs = new HashMap<String, String>();

    if (userPrefs.exists()) {
      prefs = readExistingPrefs(userPrefs);
      if (!userPrefs.delete())
        throw new WebDriverException("Cannot delete existing user preferences");
    }

    additionalPrefs.addTo(prefs);

    // Normal settings to facilitate testing
    prefs.put("app.update.auto", "false");
    prefs.put("app.update.enabled", "false");
    prefs.put("browser.download.manager.showWhenStarting", "false");
    prefs.put("browser.EULA.override", "true");
    prefs.put("browser.EULA.3.accepted", "true");
    prefs.put("browser.link.open_external", "2");
    prefs.put("browser.link.open_newwindow", "2");
    prefs.put("browser.safebrowsing.enabled", "false");
    prefs.put("browser.search.update", "false");
    prefs.put("browser.sessionstore.resume_from_crash", "false");
    prefs.put("browser.shell.checkDefaultBrowser", "false");
    prefs.put("browser.startup.page", "0");
    prefs.put("browser.tabs.warnOnClose", "false");
    prefs.put("browser.tabs.warnOnOpen", "false");
    prefs.put("dom.disable_open_during_load", "false");
    prefs.put("extensions.update.enabled", "false");
    prefs.put("extensions.update.notifyUser", "false");
    prefs.put("security.warn_entering_secure", "false");
    prefs.put("security.warn_submit_insecure", "false");
    prefs.put("security.warn_entering_secure.show_once", "false");
    prefs.put("security.warn_entering_weak", "false");
    prefs.put("security.warn_entering_weak.show_once", "false");
    prefs.put("security.warn_leaving_secure", "false");
    prefs.put("security.warn_leaving_secure.show_once", "false");
    prefs.put("security.warn_submit_insecure", "false");
    prefs.put("security.warn_viewing_mixed", "false");
    prefs.put("security.warn_viewing_mixed.show_once", "false");
    prefs.put("signon.rememberSignons", "false");
    prefs.put("startup.homepage_welcome_url", "\"about:blank\"");

    // Which port should we listen on?
    prefs.put("webdriver_firefox_port", Integer.toString(port));

    // Should we use native events?
    prefs.put("webdriver_enable_native_events", Boolean.toString(enableNativeEvents));

    // Settings to facilitate debugging the driver
    prefs.put(
        "javascript.options.showInConsole",
        "true"); // Logs errors in chrome files to the Error Console.
    prefs.put("browser.dom.window.dump.enabled", "true"); // Enables the use of the dump() statement

    writeNewPrefs(prefs);
  }
Esempio n. 2
0
  public FirefoxProfile createCopy(int port) {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    File to = new File(tmpDir, "webdriver-" + System.currentTimeMillis());
    to.mkdirs();

    FileHandler.copyDir(profileDir, to);
    FirefoxProfile profile = new FirefoxProfile(to);
    additionalPrefs.addTo(profile);
    profile.setPort(port);
    profile.updateUserPrefs();

    rememberToClean(to);

    return profile;
  }
Esempio n. 3
0
  public FirefoxProfile createCopy(int port) {
    File to = TemporaryFilesystem.createTempDir("webdriver", "profilecopy");

    try {
      FileHandler.copy(profileDir, to);
    } catch (IOException e) {
      throw new WebDriverException(
          "Cannot create copy of profile " + profileDir.getAbsolutePath(), e);
    }
    FirefoxProfile profile = new FirefoxProfile(to);
    additionalPrefs.addTo(profile);
    profile.setPort(port);
    profile.setEnableNativeEvents(enableNativeEvents);
    profile.updateUserPrefs();

    return profile;
  }
Esempio n. 4
0
  public void updateUserPrefs(File userPrefs) {
    Preferences prefs = new Preferences(onlyOverrideThisIfYouKnowWhatYouAreDoing());

    // Allow users to override these settings
    prefs.setPreference("browser.startup.homepage", "about:blank");
    // The user must be able to override this setting (to 1) in order to
    // to change homepage on Firefox 3.0
    prefs.setPreference("browser.startup.page", 0);

    if (userPrefs.exists()) {
      prefs = new Preferences(onlyOverrideThisIfYouKnowWhatYouAreDoing(), userPrefs);
      if (!userPrefs.delete()) {
        throw new WebDriverException("Cannot delete existing user preferences");
      }
    }

    additionalPrefs.addTo(prefs);

    // Should we accept untrusted certificates or not?
    prefs.setPreference(ACCEPT_UNTRUSTED_CERTS_PREF, acceptUntrustedCerts);

    prefs.setPreference(ASSUME_UNTRUSTED_ISSUER_PREF, untrustedCertIssuer);

    // If the user sets the home page, we should also start up there
    Object homePage = prefs.getPreference("browser.startup.homepage");
    if (homePage != null && homePage instanceof String) {
      prefs.setPreference("startup.homepage_welcome_url", "");
    }

    if (!"about:blank".equals(prefs.getPreference("browser.startup.homepage"))) {
      prefs.setPreference("browser.startup.page", 1);
    }

    try (FileWriter writer = new FileWriter(userPrefs)) {
      prefs.writeTo(writer);
    } catch (IOException e) {
      throw new WebDriverException(e);
    }
  }
Esempio n. 5
0
  @VisibleForTesting
  @Beta
  protected FirefoxProfile(Reader defaultsReader, File profileDir) {
    if (defaultsReader == null) {
      defaultsReader = onlyOverrideThisIfYouKnowWhatYouAreDoing();
    }

    additionalPrefs = new Preferences(defaultsReader);

    model = profileDir;
    verifyModel(model);

    File prefsInModel = new File(model, "user.js");
    if (prefsInModel.exists()) {
      StringReader reader = new StringReader("{\"frozen\": {}, \"mutable\": {}}");
      Preferences existingPrefs = new Preferences(reader, prefsInModel);
      acceptUntrustedCerts =
          getBooleanPreference(
              existingPrefs, ACCEPT_UNTRUSTED_CERTS_PREF, ACCEPT_UNTRUSTED_CERTIFICATES);
      untrustedCertIssuer =
          getBooleanPreference(
              existingPrefs, ASSUME_UNTRUSTED_ISSUER_PREF, ASSUME_UNTRUSTED_ISSUER);
      existingPrefs.addTo(additionalPrefs);
    } else {
      acceptUntrustedCerts = ACCEPT_UNTRUSTED_CERTIFICATES;
      untrustedCertIssuer = ASSUME_UNTRUSTED_ISSUER;
    }

    // This is not entirely correct but this is not stored in the profile
    // so for now will always be set to false.
    loadNoFocusLib = false;

    try {
      defaultsReader.close();
    } catch (IOException e) {
      throw new WebDriverException(e);
    }
  }