/** Initialization needed for tests. Mainly used by content browsertests. */
  public void initChromiumBrowserProcessForTests() {
    ResourceExtractor resourceExtractor = ResourceExtractor.get(mContext);
    resourceExtractor.startExtractingResources();
    resourceExtractor.waitForCompletion();

    // Having a single renderer should be sufficient for tests. We can't have more than
    // MAX_RENDERERS_LIMIT.
    nativeSetCommandLineFlags(1 /* maxRenderers */, null);
  }
Beispiel #2
0
 @Before
 public void setUp() throws Exception {
   ResourceExtractor resourceExtractor = new ResourceExtractor();
   resourceExtractor.addLocalRClass(R.class);
   resourceExtractor.addSystemRClass(android.R.class);
   colorResourceLoader = new ColorResourceLoader(resourceExtractor);
   new DocumentLoader(colorResourceLoader).loadResourceXmlDir(resourceFile("res", "values"));
   new DocumentLoader(colorResourceLoader)
       .loadSystemResourceXmlDir(getSystemResourceDir("values"));
 }
  @VisibleForTesting
  void prepareToStartBrowserProcess(int maxRendererProcesses) throws ProcessInitException {
    Log.i(TAG, "Initializing chromium process, renderers=" + maxRendererProcesses);

    // Normally Main.java will have kicked this off asynchronously for Chrome. But other
    // ContentView apps like tests also need them so we make sure we've extracted resources
    // here. We can still make it a little async (wait until the library is loaded).
    ResourceExtractor resourceExtractor = ResourceExtractor.get(mContext);
    resourceExtractor.startExtractingResources();

    // Normally Main.java will have already loaded the library asynchronously, we only need
    // to load it here if we arrived via another flow, e.g. bookmark access & sync setup.
    LibraryLoader.ensureInitialized(mContext);

    // TODO(yfriedman): Remove dependency on a command line flag for this.
    DeviceUtils.addDeviceSpecificUserAgentSwitch(mContext);

    Context appContext = mContext.getApplicationContext();
    // Now we really need to have the resources ready.
    resourceExtractor.waitForCompletion();

    nativeSetCommandLineFlags(maxRendererProcesses, nativeIsPluginEnabled() ? getPlugins() : null);
    ContentMain.initApplicationContext(appContext);
  }
  private File createExtractedFiles() {
    final File userExtensionsJavascriptFile;
    final File userExtensions;
    final File coreDir;

    coreDir = new File(customProfileDir, "core");
    try {
      coreDir.mkdirs();
      ResourceExtractor.extractResourcePath(SafariFileBasedLauncher.class, "/core", coreDir);
      // custom user-extensions
      userExtensions = getConfiguration().getUserExtensions();
      if (userExtensions != null) {
        userExtensionsJavascriptFile = new File(coreDir, "scripts/user-extensions.js");
        FileUtils.getFileUtils().copyFile(userExtensions, userExtensionsJavascriptFile, null, true);
      }
      return new File(coreDir, "RemoteRunner.html");
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 @Test
 public void shouldReturnRawResourcesWithoutExtensions() throws Exception {
   FsFile f = rawResourceFiles.get(resourceIndex.getResName(R.raw.raw_no_ext), "");
   assertThat(f).isEqualTo(TEST_RESOURCE_PATH.rawDir.join("raw_no_ext"));
 }
  private void initialize(Context context) {

    Log.i("Ludei", "***************************");
    Log.i("Ludei", "Initializing Ludei WebView+");
    Log.i("Ludei", "**************************");

    if (!staticInitialization) {
      PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
      ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES);
      ResourceProvider.registerResources();
      staticInitialization = true;
    }

    this.ctx = context;
    if (mProxyWebView == null) {
      mProxyWebView = new LudeiWebView(context, null, 0, this);
    }
    mBridge =
        new LudeiContentsClientBridge(
            mProxyWebView, new LudeiDefaultWebChromeClient(this.ctx, this));
    mDelegate = new LudeiContentViewDelegate(this, mBridge);

    // Initializing the command line must occur before loading the library.
    if (!CommandLine.isInitialized()) {
      CommandLine.initFromFile(COMMAND_LINE_FILE);
      String[] commandLineParams = null; // getCommandLineParamsFromIntent(getIntent());

      if (commandLineParams != null) {
        CommandLine.getInstance().appendSwitchesAndArguments(commandLineParams);
      }
      CommandLine.getInstance().appendSwitch("allow-file-access-from-files");
      if (!LudeiContentView.REMOTE_DEBUGGING) {
        CommandLine.getInstance().appendSwitch("disable-remote-debugging");
      }
      CommandLine.getInstance().appendSwitch("ignore-gpu-blacklist");
    }
    waitForDebuggerIfNeeded();

    DeviceUtils.addDeviceSpecificUserAgentSwitch(context);
    try {
      org.chromium.base.library_loader.LibraryLoader.ensureInitialized();
    } catch (ProcessInitException e) {
      Log.e(TAG, "ContentView initialization failed.", e);
      // Since the library failed to initialize nothing in the application
      // can work, so kill the whole application not just the activity
      System.exit(-1);
      return;
    }

    mSettings = LudeiWebSettingsProxy.Create(context, (new LudeiWebSettings(context, true, false)));
    shellManager = new ShellManager(context, null, this, mDelegate);

    WindowAndroid mWindowAndroid = new ActivityWindowAndroid((Activity) ctx);
    // mWindowAndroid.restoreInstanceState(savedInstanceState);
    shellManager.setWindow(
        mWindowAndroid,
        new Runnable() {
          @Override
          public void run() {
            LudeiContentView.this.onReadyToRender();
          }
        });

    if (CommandLine.getInstance().hasSwitch(ContentSwitches.DUMP_RENDER_TREE)) {
      try {
        BrowserStartupController.get(context).startBrowserProcessesSync(true);
      } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to load native library.", e);
        System.exit(-1);
      }
    } else {
      try {
        BrowserStartupController.get(context)
            .startBrowserProcessesAsync(
                new BrowserStartupController.StartupCallback() {
                  @Override
                  public void onSuccess(boolean alreadyStarted) {
                    // finishInitialization(savedInstanceState);
                    finishInitialization(null);
                  }

                  @Override
                  public void onFailure() {
                    initializationFailed();
                  }
                });
      } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        System.exit(-1);
      }
    }
  }