Example #1
0
    def TestSampleHelloCube_TexturesSmall(self):
        """Validates loading of files from an external source."""

        # Alias for the selenium session
        s = self.session
        s.open(self.GetURL("/samples/hellocube-textures.html"))

        # Sanity checks.
        self.assertEqual(
            "Hello Square Textures: Getting started with O3D, take 3.",
            s.get_title())
        self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))

        # Allow a limited time for the plugin to initialize.
        s.wait_for_condition(
            "(typeof(window.g_finished) != 'undefined') && "
            "window.g_finished == true;", 10000)

        # if they are animated we need to stop the animation and set the clock
        # to some time so we get a known state.
        s.run_script("g_timeMult = 0")
        s.run_script("g_clock = 27.5")

        # Take screenshot
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "hellocube-textures1"))
  def TestSampleShader_Test(self):
    """Tests shader-test.html."""

    # Alias for the selenium session
    s = self.session
    s.open(s.browserURL + "/samples/shader-test.html")

    # Allow a limited time for the plugin to initialize.
    s.wait_for_condition("typeof(window.g_client) != 'undefined';", 20000)

    # Sanity checks.
    self.assertEqual("Shader Test", s.get_title())
    self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))

    # wait for it to initialize.
    s.wait_for_condition("(typeof(window.g_finished) != 'undefined') && "
                         "window.g_finished == true;",
                         20000)

    # if they are animated we need to stop the animation and set the clock
    # to some time so we get a known state.
    s.run_script("g_timeMult = 0")
    s.run_script("g_clock = 27.5")

    # Figure out how many options there are.
    num_shaders = s.get_eval(
        "window.document.getElementById('shaderSelect').length")

    # try each shader
    for shader in range(0, int(num_shaders)):
      # select shader
      s.select("//select[@id='shaderSelect']", ("index=%d" % shader))
      # Take screenshot
      self.assertTrue(selenium_utilities.TakeScreenShot(
          s, self.browser, "g_client", ("shader-test%d" % shader)))
Example #3
0
    def TestSampleErrorTextureSmall(self):
        """Tests error-texture.html."""

        # Alias for the selenium session
        s = self.session
        s.open(self.GetURL("/samples/error-texture.html"))

        # Allow a limited time for the plugin to initialize.
        s.wait_for_condition("typeof(window.g_client) != 'undefined';", 30000)

        # Sanity checks.
        self.assertEqual("Error Texture", s.get_title())
        self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))

        # Take screenshots
        time.sleep(2)  # helps with Vista FF screencapture
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "errortexture1"))
        s.click("//input[@value='User Texture']")
        s.wait_for_condition("(window.g_errorMsgElement.innerHTML=='-');",
                             1000)
        time.sleep(2)  # helps with Vista FF screencapture
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "errortexture2"))
        s.click("//input[@value='No Texture']")
        s.wait_for_condition(
            "(window.g_errorMsgElement.innerHTML=="
            "'Missing texture for sampler s2d');", 1000)
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "errortexture3"))
        s.click("//input[@value='hide 0']")
        s.wait_for_condition(
            "(window.g_errorMsgElement.innerHTML=="
            "'Missing Sampler for ParamSampler texSampler0');", 1000)
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "errortexture4"))
        s.click("//input[@value='hide 1']")
        s.wait_for_condition(
            "(window.g_errorMsgElement.innerHTML=="
            "'Missing ParamSampler');", 1000)
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "errortexture5"))
  def TestSampleCustomCamera(self):
    """Tests customcamera.html."""

    # Alias for the selenium session
    s = self.session
    s.open(s.browserURL + "/samples/customcamera.html")

    # Allow a limited time for the plugin to initialize.
    s.wait_for_condition("typeof(window.g_client) != 'undefined';", 10000)

    # Sanity checks.
    self.assertEqual("Tutorial B4: Cameras and events", s.get_title())
    self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))

    # Try different views of the camera
    time.sleep(1)
    s.type("eyeX", "5")
    time.sleep(1)
    s.type("eyeY", "5")
    time.sleep(1)
    s.type("eyeZ", "5")
    time.sleep(1)
    s.click("btnSet")

    time.sleep(1)
    s.type("eyeX", "2")
    time.sleep(1)
    s.type("eyeY", "3")
    time.sleep(1)
    s.type("eyeZ", "2")
    time.sleep(1)
    s.type("upX", "1")
    time.sleep(1)
    s.type("upY", "0")
    time.sleep(1)
    s.click("btnSet")
    time.sleep(2)

    # Capture screenshot
    self.assertTrue(selenium_utilities.TakeScreenShot(s, self.browser,
                                                      "g_client",
                                                      "customcamera1"))

    # Reset view
    s.click("btnDefault")
Example #5
0
    def TestSampleCustomCamera(self):
        """Tests customcamera.html."""

        # Alias for the selenium session
        s = self.session
        s.open(self.GetURL("/samples/customcamera.html"))

        # Allow a limited time for the plugin to initialize.
        s.wait_for_condition("typeof(window.g_client) != 'undefined';", 10000)

        # Sanity checks.
        self.assertEqual("Tutorial B4: Cameras and events", s.get_title())
        self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))

        # Try different views of the camera.
        # Set delay between each operation at 100ms. This is needed for some
        # versions of IE and Chrome.
        speed = int(s.get_speed())
        s.set_speed(100)
        s.type("eyeX", "5")
        s.type("eyeY", "5")
        s.type("eyeZ", "5")
        s.click("btnSet")

        s.type("eyeX", "2")
        s.type("eyeY", "3")
        s.type("eyeZ", "2")
        s.type("upX", "1")
        s.type("upY", "0")
        s.click("btnSet")
        # Reset delay to previous value.
        s.set_speed(speed)

        # Capture screenshot
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "customcamera1"))

        # Reset view
        s.click("btnDefault")
Example #6
0
    def TestStressCullingZSort(self):
        """Checks culling and zsorting work."""

        # Alias for the selenium session
        s = self.session
        s.open(s.browserURL + "/tests/selenium/tests/culling-zsort-test.html")

        # Allow a limited time for the plugin to initialize.
        s.wait_for_condition("typeof(window.g_client) != 'undefined';", 20000)

        # Sanity checks.
        self.assertEqual("Culling and ZSorting Test.", s.get_title())
        self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))
        s.wait_for_condition("window.g_client != null", 10000)

        # Wait for all instances to be created.
        s.wait_for_condition(
            "window.g_totalDrawElementsElement.innerHTML == '2'", 40000)

        # Stop animation
        s.run_script("g_timeMult = 0")
        s.run_script("g_client.renderMode = g_o3d.Client.RENDERMODE_ON_DEMAND")
        s.run_script("var g_rendered = false")

        new_data = []
        culling_reference_data = [[1793, 4472, 3780, 2, 4844, 213, 4631],
                                  [1793, 6011, 3854, 2, 7734, 337, 7397],
                                  [1793, 3014, 2416, 2, 3400, 121, 3279],
                                  [1793, 2501, 2408, 2, 2420, 162, 2258],
                                  [1793, 2933, 2914, 2, 2746, 182, 2564],
                                  [1793, 2825, 2848, 2, 2604, 171, 2433],
                                  [1793, 2933, 2790, 2, 2870, 155, 2715],
                                  [1793, 4337, 3004, 2, 5360, 237, 5123]]

        # Take screenshots
        for clock in range(0, 8):
            s.run_script("window.g_clock = " +
                         str(clock * 3.14159 * 2.5 + 0.5))
            self.assertTrue(
                selenium_utilities.TakeScreenShot(s, self.browser,
                                                  "window.g_client",
                                                  "cullingzsort" + str(clock)))
            s.run_script("g_framesRendered = 0")
            while int(s.get_eval("window.g_framesRendered")) < 3:
                s.run_script("window.g_client.render()")
            data = [
                s.get_eval("window.g_totalTransformsElement.innerHTML"),
                s.get_eval("window.g_transformsProcessedElement.innerHTML"),
                s.get_eval("window.g_transformsCulledElement.innerHTML"),
                s.get_eval("window.g_totalDrawElementsElement.innerHTML"),
                s.get_eval("window.g_drawElementsProcessedElement.innerHTML"),
                s.get_eval("window.g_drawElementsCulledElement.innerHTML"),
                s.get_eval("window.g_drawElementsRenderedElement.innerHTML")
            ]
            new_data.append(data)
            print ", ".join(data)

        # check the results
        for clock in range(0, 8):
            for ii in range(0, 7):
                # comment out the following line and add a "pass" line if you need new
                # culling reference data.
                self.assertEqual(int(new_data[clock][ii]),
                                 culling_reference_data[clock][ii])
Example #7
0
    def TestSampleRotateModel(self):
        """Tests rotatemodel.html."""

        # Alias for the selenium session
        s = self.session
        s.open(self.GetURL("/samples/rotatemodel.html"))

        # wait for sample to be ready.
        s.wait_for_condition(
            "(typeof(window.g_finished) != 'undefined') && "
            "window.g_finished == true;", 50000)

        # Capture screenshot
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "rotatemodel1"))

        # Check that local matrix is the identity
        self.AssertEqualMatrix4("window.g_math.matrix4.identity()",
                                "window.g_sceneRoot.localMatrix")

        # TODO:  s.key_press is not functioning on Chrome, so we revert
        #  to button-based testing of the rotation functions on this platform.
        #  Remove this test when chrome keyboard input works in selenium.
        browser_is_chrome = self.browser == "*googlechrome"

        # Rotate slightly
        if browser_is_chrome:
            s.click("A")
        else:
            s.key_press("document.getElementById('o3d')", "a")

        # Check that rotation matrix is correct
        self.AssertEqualMatrix4(
            "window.g_math.matrix4.rotationZYX([0, -0.05, 0])",
            "window.g_sceneRoot.localMatrix")

        # Rotate model
        for unused_i in range(1, 10):
            if browser_is_chrome:
                s.click("W")
            else:
                s.key_press("document.getElementById('o3d')", "w")

        for unused_i in range(1, 5):
            if browser_is_chrome:
                s.click("S")
            else:
                s.key_press("document.getElementById('o3d')", "s")

        for unused_i in range(1, 5):
            if browser_is_chrome:
                s.click("A")
            else:
                s.key_press("document.getElementById('o3d')", "a")

        for unused_i in range(1, 10):
            if browser_is_chrome:
                s.click("D")
            else:
                s.key_press("document.getElementById('o3d')", "d")

        # Capture screenshot
        self.assertTrue(
            selenium_utilities.TakeScreenShot(s, self.browser, "g_client",
                                              "rotatemodel2"))

        # Reset view
        s.click("//input[@value='Reset view']")