コード例 #1
0
ファイル: run_tests.py プロジェクト: crackself/iceweasel
def view_gecko_profile_from_talos():
    profile_zip_path = os.environ.get("TALOS_LATEST_GECKO_PROFILE_ARCHIVE", None)
    if profile_zip_path is None or not os.path.exists(profile_zip_path):
        LOG.info(
            "No local talos gecko profiles were found so not launching profiler.firefox.com"
        )
        return

    LOG.info("Profile saved locally to: %s" % profile_zip_path)
    view_gecko_profile(profile_zip_path)
コード例 #2
0
def view_gecko_profile_from_raptor():
    # automatically load the latest raptor gecko-profile archive in profiler.firefox.com
    LOG_GECKO = RaptorLogger(component='raptor-view-gecko-profile')

    profile_zip_path = os.environ.get('RAPTOR_LATEST_GECKO_PROFILE_ARCHIVE', None)
    if profile_zip_path is None or not os.path.exists(profile_zip_path):
        LOG_GECKO.info("No local raptor gecko profiles were found so not "
                       "launching profiler.firefox.com")
        return

    LOG_GECKO.info("Profile saved locally to: %s" % profile_zip_path)
    view_gecko_profile(profile_zip_path)
コード例 #3
0
    def test_view_gecko_profile(self):

        # Create a temporary fake performance profile.
        temp_dir = tempfile.mkdtemp()
        profile_path = os.path.join(temp_dir, "fakeprofile.json")
        with io.open(profile_path, "w") as f:
            f.write(u"FAKE_PROFILE")

        # Mock the open_new_tab function so that we know when the view_gecko_profile
        # function has done all of its work, and we can assert ressult of the
        # user behavior.
        def mocked_open_new_tab(firefox_profiler_url):
            self.firefox_profiler_url = firefox_profiler_url
            encoded_file_url = firefox_profiler_url.split("/")[-1]
            decoded_file_url = unquote(encoded_file_url)
            # Extract the actual file from the path.
            self.thread = threading.Thread(target=access_profiler_link,
                                           args=(decoded_file_url,
                                                 self.response))
            print("firefox_profiler_url %s" % firefox_profiler_url)
            print("encoded_file_url %s" % encoded_file_url)
            print("decoded_file_url %s" % decoded_file_url)
            self.thread.start()

        with mock.patch("webbrowser.open_new_tab", new=mocked_open_new_tab):
            # Run the test
            view_gecko_profile(profile_path)

        self.thread.join()

        # Compare the URLs, but replace the PORT value supplied, as that is dynamic.
        expected_url = ("https://profiler.firefox.com/from-url/"
                        "http%3A%2F%2F127.0.0.1%3A{PORT}%2Ffakeprofile.json")
        actual_url = re.sub("%3A\d+%2F", "%3A{PORT}%2F",
                            self.firefox_profiler_url)

        self.assertEqual(
            actual_url,
            expected_url,
            "The URL generated was correct for the Firefox Profiler.",
        )
        self.assertEqual(
            self.response[0],
            "FAKE_PROFILE",
            "The response from the serve provided the profile contents.",
        )

        shutil.rmtree(temp_dir)